[check_cs] Fixed and optimized the coding standard script

[check_cs] Optimized coding standards script

* Defined skipped files array outside of foreach loop
* Reduced calls to $file->getRealPath() to one

[check_cs] Fixed skipped file paths

Paths to skipped files have changed since test files have been moved
into individual components

[check_cs] Optimized coding standards script

* Removed nested foreach loop

[check_cs] Minor formatting change
This commit is contained in:
Andy Cox 2012-05-11 12:32:56 +01:00
parent 554e073822
commit 0bcc5fa210

View File

@ -28,35 +28,35 @@ $finder
->name('*.yml')
->in(__DIR__.'/src')
->notName(basename(__FILE__))
->notName('sfTests.yml')
->exclude('.git')
->exclude('vendor')
;
// These files are skipped because tests would break
$skippedFiles = array_map('realpath', array(
'src/Symfony/Component/ClassLoader/Tests/ClassCollectionLoaderTest.php',
'src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container9.php',
'src/Symfony/Component/DependencyInjection/Tests/Fixtures/includes/foo.php',
'src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services9.php',
'src/Symfony/Component/DependencyInjection/Tests/Fixtures/yaml/services9.yml',
'src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher1.php',
'src/Symfony/Component/Routing/Tests/Fixtures/dumper/url_matcher2.php',
'src/Symfony/Component/Yaml/Tests/Fixtures/sfTests.yml',
));
$count = 0;
foreach ($finder as $file) {
/* @var $file Symfony\Component\Finder\SplFileInfo */
// These files are skipped because tests would break
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) {
$path = $file->getRealPath();
if ($skippedFile === substr($file->getRealPath(), strlen($skippedFile) * -1)) {
continue(2);
}
if (in_array($path, $skippedFiles)) {
continue;
}
$old = file_get_contents($file->getRealpath());
$old = file_get_contents($path);
$new = $old;
@ -103,7 +103,7 @@ foreach ($finder as $file) {
$count++;
if ($fix) {
file_put_contents($file->getRealpath(), $new);
file_put_contents($path, $new);
}
printf('%4d) %s'.PHP_EOL, $count, $file->getRelativePathname());
}