From 5f8a0f5d23aaf9510699581a57796ee3a763e4b5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 8 Jun 2011 11:24:35 +0200 Subject: [PATCH] made some tweaks to the check_cs script --- check_cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/check_cs b/check_cs index 5762128695..b75d2d4768 100755 --- a/check_cs +++ b/check_cs @@ -14,6 +14,8 @@ require_once __DIR__.'/autoload.php.dist'; use Symfony\Component\Finder\Finder; +$fix = isset($argv[1]) && 'fix' == $argv[1]; + $finder = new Finder(); $finder ->files() @@ -24,14 +26,14 @@ $finder ->name('*.xml') ->name('*.xml.dist') ->name('*.yml') - ->in(__DIR__) + ->in(__DIR__.'/src', __DIR__.'/tests') ->notName(basename(__FILE__)) ->exclude('.git') ->exclude('vendor') ; -foreach ($finder as $file) { /* @var $file Symfony\Component\Finder\SplFileInfo */ - +$exit = 0; +foreach ($finder as $file) { // These files are skipped because tests would break if (in_array($file->getRelativePathname(), array( 'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php', @@ -55,7 +57,7 @@ foreach ($finder as $file) { /* @var $file Symfony\Component\Finder\SplFileInfo // [Structure] Indentation is done by steps of four spaces (tabs are never allowed); $new = preg_replace_callback('/^( *)(\t+)/m', function ($matches) use ($new) { - return $matches[1] . str_repeat(' ', strlen($matches[2])); + return $matches[1].str_repeat(' ', strlen($matches[2])); }, $new); // [Structure] Use the linefeed character (0x0A) to end lines; @@ -68,7 +70,13 @@ foreach ($finder as $file) { /* @var $file Symfony\Component\Finder\SplFileInfo $new = preg_replace('/([^ {|\n]$)(\n return .+?$\n \}$)/m', '$1'."\n".'$2', $new); if ($new != $old) { - file_put_contents($file->getRealpath(), $new); - echo $file->getRelativePathname() . PHP_EOL; + $exit = 1; + if ($fix) { + file_put_contents($file->getRealpath(), $new); + } + + echo $file->getRelativePathname().PHP_EOL; } } + +exit($exit);