8000 Merge remote branch 'brikou/check_cs' · 77web/symfony@4c01d64 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c01d64

Browse files
committed
Merge remote branch 'brikou/check_cs'
* brikou/check_cs: fixed root search path to include only './src' and './tests' fixed 'base search dir' + fixed 'blank line inserted' when line before ends with colon
2 parents e685b5f + cd2a7bb commit 4c01d64

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

check_cs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,20 @@ $finder
2626
->name('*.xml')
2727
->name('*.xml.dist')
2828
->name('*.yml')
29-
->in(__DIR__.'/src', __DIR__.'/tests')
29+
->in(array(__DIR__.'/src', __DIR__.'/tests'))
3030
->notName(basename(__FILE__))
3131
->exclude('.git')
3232
->exclude('vendor')
3333
;
3434

35-
$exit = 0;
35+
$count = 0;
36+
3637
foreach ($finder as $file) {
38+
39+
/* @var $file Symfony\Component\Finder\SplFileInfo */
40+
3741
// These files are skipped because tests would break
38-
if (in_array($file->getRelativePathname(), array(
42+
foreach(array(
3943
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php',
4044
'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php',
4145
'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/includes/foo.php',
@@ -44,8 +48,11 @@ foreach ($finder as $file) {
4448
'tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php',
4549
'tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php',
4650
'tests/Symfony/Tests/Component/Yaml/Fixtures/sfTests.yml',
47-
))) {
48-
continue;
51+
) as $skippedFile) {
52+
53+
if ($skippedFile === substr($file->getRealPath(), strlen($skippedFile) * -1)) {
54+
continue(2);
55+
}
4956
}
5057

5158
$old = file_get_contents($file->getRealpath());
@@ -68,30 +75,32 @@ foreach ($finder as $file) {
6875

6976
// [Structure] Add a blank line before return statements
7077
$new = preg_replace_callback('/(^.*$)\n(^ +return)/m', function ($match) {
71-
// don't add it if the previous line is
72-
// * {
73-
// * :
74-
// * already blank line
75-
if (preg_match('#(\{ *$|^$|^ *//|\:)#', $match[1])) {
78+
// don't add it if the previous line is ...
79+
if (
80+
preg_match('/\{$/m', $match[1]) || // ... ending with an opening brace
81+
preg_match('/\:$/m', $match[1]) || // ... ending with a colon (e.g. a case statement)
82+
preg_match('%^ *//%m', $match[1]) || // ... an inline comment
83+
preg_match('/^$/m', $match[1]) // ... already blank
84+
) {
7685
return $match[1]."\n".$match[2];
7786
}
7887

7988
return $match[1]."\n\n".$match[2];
8089
}, $new);
8190

8291
// [Structure] A file must always ends with a linefeed character
83-
if (strlen($new) && "\n" != $new[strlen($new) - 1]) {
92+
if (strlen($new) && "\n" != substr($new, -1)) {
8493
$new .= "\n";
8594
}
8695

8796
if ($new != $old) {
88-
$exit = 1;
97+
$count++;
98+
8999
if ($fix) {
90100
file_put_contents($file->getRealpath(), $new);
91101
}
92-
93-
echo $file->getRelativePathname().PHP_EOL;
102+
printf('%4d) %s'.PHP_EOL, $count, $file->getRelativePathname());
94103
}
95104
}
96105

97-
exit($exit);
106+
exit($count ? 1 : 0);

0 commit comments

Comments
 (0)
0