@@ -26,16 +26,20 @@ $finder
26
26
->name ('*.xml ' )
27
27
->name ('*.xml.dist ' )
28
28
->name ('*.yml ' )
29
- ->in (__DIR__ .'/src ' , __DIR__ .'/tests ' )
29
+ ->in (array ( __DIR__ .'/src ' , __DIR__ .'/tests ' ) )
30
30
->notName (basename (__FILE__ ))
31
31
->exclude ('.git ' )
32
32
->exclude ('vendor ' )
33
33
;
34
34
35
- $ exit = 0 ;
35
+ $ count = 0 ;
36
+
36
37
foreach ($ finder as $ file ) {
38
+
39
+ /* @var $file Symfony\Component\Finder\SplFileInfo */
40
+
37
41
// These files are skipped because tests would break
38
- if ( in_array ( $ file -> getRelativePathname (), array (
42
+ foreach ( array (
39
43
'tests/Symfony/Tests/Component/ClassLoader/ClassCollectionLoaderTest.php ' ,
40
44
'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/containers/container9.php ' ,
41
45
'tests/Symfony/Tests/Component/DependencyInjection/Fixtures/includes/foo.php ' ,
@@ -44,8 +48,11 @@ foreach ($finder as $file) {
44
48
'tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php ' ,
45
49
'tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php ' ,
46
50
'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
+ }
49
56
}
50
57
51
58
$ old = file_get_contents ($ file ->getRealpath ());
@@ -68,30 +75,32 @@ foreach ($finder as $file) {
68
75
69
76
// [Structure] Add a blank line before return statements
70
77
$ 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
+ ) {
76
85
return $ match [1 ]."\n" .$ match [2 ];
77
86
}
78
87
79
88
return $ match [1 ]."\n\n" .$ match [2 ];
80
89
}, $ new );
81
90
82
91
// [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 ) ) {
84
93
$ new .= "\n" ;
85
94
}
86
95
87
96
if ($ new != $ old ) {
88
- $ exit = 1 ;
97
+ $ count ++;
98
+
89
99
if ($ fix ) {
90
100
file_put_contents ($ file ->getRealpath (), $ new );
91
101
}
92
-
93
- echo $ file ->getRelativePathname ().PHP_EOL ;
102
+ printf ('%4d) %s ' .PHP_EOL , $ count , $ file ->getRelativePathname ());
94
103
}
95
104
}
96
105
97
- exit ($ exit );
106
+ exit ($ count ? 1 : 0 );
0 commit comments