@@ -26,14 +26,17 @@ $finder
26
26
->name ('*.xml ' )
27
27
->name ('*.xml.dist ' )
28
28
->name ('*.yml ' )
29
- ->in (__DIR__ . ' /src ' , __DIR__ . ' /tests ' )
29
+ ->in (__DIR__ )
30
30
->notName (basename (__FILE__ ))
31
31
->exclude ('.git ' )
32
32
->exclude ('vendor ' )
33
33
;
34
34
35
35
$ exit = 0 ;
36
36
foreach ($ finder as $ file ) {
37
+
38
+ /* @var $file Symfony\Component\Finder\SplFileInfo */
39
+
37
40
// These files are skipped because tests would break
38
41
if (in_array ($ file ->getRelativePathname (), array (
39
42
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php ' ,
@@ -68,19 +71,21 @@ foreach ($finder as $file) {
68
71
69
72
// [Structure] Add a blank line before return statements
70
73
$ 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 ])) {
74
+ // don't add it if the previous line is ...
75
+ if (
76
+ preg_match ('/\{$/m ' , $ match [1 ]) || // ... ending with an opening brace
77
+ preg_match ('/\:$/m ' , $ match [1 ]) || // ... ending with a colon (e.g. a case statement)
78
+ preg_match ('%^ *//%m ' , $ match [1 ]) || // ... an inline comment
79
+ preg_match ('/^$/m ' , $ match [1 ]) // ... already blank
80
+ ) {
76
81
return $ match [1 ]."\n" .$ match [2 ];
77
82
}
78
83
79
84
return $ match [1 ]."\n\n" .$ match [2 ];
80
85
}, $ new );
81
86
82
87
// [Structure] A file must always ends with a linefeed character
83
- if (strlen ($ new ) && "\n" != $ new [ strlen ($ new) - 1 ] ) {
88
+ if (strlen ($ new ) && "\n" != substr ($ new, - 1 ) ) {
84
89
$ new .= "\n" ;
85
90
}
86
91
0 commit comments