made some tweaks to the check_cs script

This commit is contained in:
Fabien Potencier 2011-06-08 11:24:35 +02:00
parent d5cfb1cfda
commit 5f8a0f5d23

View File

@ -14,6 +14,8 @@ require_once __DIR__.'/autoload.php.dist';
use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\Finder;
$fix = isset($argv[1]) && 'fix' == $argv[1];
$finder = new Finder(); $finder = new Finder();
$finder $finder
->files() ->files()
@ -24,14 +26,14 @@ $finder
->name('*.xml') ->name('*.xml')
->name('*.xml.dist') ->name('*.xml.dist')
->name('*.yml') ->name('*.yml')
->in(__DIR__) ->in(__DIR__.'/src', __DIR__.'/tests')
->notName(basename(__FILE__)) ->notName(basename(__FILE__))
->exclude('.git') ->exclude('.git')
->exclude('vendor') ->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 // These files are skipped because tests would break
if (in_array($file->getRelativePathname(), array( if (in_array($file->getRelativePathname(), array(
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php', '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); // [Structure] Indentation is done by steps of four spaces (tabs are never allowed);
$new = preg_replace_callback('/^( *)(\t+)/m', function ($matches) use ($new) { $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); }, $new);
// [Structure] Use the linefeed character (0x0A) to end lines; // [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); $new = preg_replace('/([^ {|\n]$)(\n return .+?$\n \}$)/m', '$1'."\n".'$2', $new);
if ($new != $old) { if ($new != $old) {
file_put_contents($file->getRealpath(), $new); $exit = 1;
echo $file->getRelativePathname() . PHP_EOL; if ($fix) {
file_put_contents($file->getRealpath(), $new);
}
echo $file->getRelativePathname().PHP_EOL;
} }
} }
exit($exit);