123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
-
- <?php
-
-
- require_once __DIR__.'/autoload.php.dist';
-
- use Symfony\Component\Finder\Finder;
-
- $fix = isset($argv[1]) && 'fix' == $argv[1];
-
- $finder = new Finder();
- $finder
- ->files()
- ->name('*.md')
- ->name('*.php')
- ->name('*.php.dist')
- ->name('*.twig')
- ->name('*.xml')
- ->name('*.xml.dist')
- ->name('*.yml')
- ->in(array(__DIR__.'/src', __DIR__.'/tests'))
- ->notName(basename(__FILE__))
- ->exclude('.git')
- ->exclude('vendor')
- ;
-
- $count = 0;
-
- foreach ($finder as $file) {
-
-
-
-
- foreach(array(
- 'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php',
- 'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php',
- 'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/includes/foo.php',
- 'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/php/services9.php',
- 'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/yaml/services9.yml',
- 'tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php',
- 'tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php',
- 'tests/Symfony/Tests/Component/Yaml/Fixtures/sfTests.yml',
- ) as $skippedFile) {
-
- if ($skippedFile === substr($file->getRealPath(), strlen($skippedFile) * -1)) {
- continue(2);
- }
- }
-
- $old = file_get_contents($file->getRealpath());
-
- $new = $old;
-
-
- $new = str_replace('<? ', '<?php ', $new);
-
-
- $new = preg_replace_callback('/^( *)(\t+)/m', function ($matches) use ($new) {
- return $matches[1].str_repeat(' ', strlen($matches[2]));
- }, $new);
-
-
- $new = str_replace("\r\n", "\n", $new);
-
-
- $new = preg_replace('/[ \t]*$/m', '', $new);
-
-
- $new = preg_replace_callback('/(^.*$)\n(^ +return)/m', function ($match) {
-
- if (
- preg_match('/\{$/m', $match[1]) ||
- preg_match('/\:$/m', $match[1]) ||
- preg_match('%^ *//%m', $match[1]) ||
- preg_match('/^$/m', $match[1])
- ) {
- return $match[1]."\n".$match[2];
- }
-
- return $match[1]."\n\n".$match[2];
- }, $new);
-
-
- if (strlen($new) && "\n" != substr($new, -1)) {
- $new .= "\n";
- }
-
- if ($new != $old) {
- $count++;
-
- if ($fix) {
- file_put_contents($file->getRealpath(), $new);
- }
- printf('%4d) %s'.PHP_EOL, $count, $file->getRelativePathname());
- }
- }
-
- exit($count ? 1 : 0);
|