77use PHPStan \File \FileExcluder ;
88use function array_key_exists ;
99use function array_map ;
10- use function array_merge ;
1110use function count ;
1211use function is_dir ;
1312use function is_file ;
@@ -27,41 +26,42 @@ public function loadConfiguration(): void
2726 return ;
2827 }
2928
29+ $ newExcludePaths = [];
30+ if (array_key_exists ('analyseAndScan ' , $ excludePaths )) {
31+ $ newExcludePaths ['analyseAndScan ' ] = $ excludePaths ['analyseAndScan ' ];
32+ }
33+ if (array_key_exists ('analyse ' , $ excludePaths )) {
34+ $ newExcludePaths ['analyse ' ] = $ excludePaths ['analyse ' ];
35+ }
36+
3037 $ errors = [];
38+ $ suggestOptional = [];
3139 if ($ builder ->parameters ['__validate ' ]) {
32- $ paths = [];
33- if (array_key_exists ('analyse ' , $ excludePaths )) {
34- $ paths = $ excludePaths ['analyse ' ];
35- }
36- if (array_key_exists ('analyseAndScan ' , $ excludePaths )) {
37- $ paths = array_merge ($ paths , $ excludePaths ['analyseAndScan ' ]);
38- }
39- foreach ($ paths as $ path ) {
40- if ($ path instanceof OptionalPath) {
41- continue ;
42- }
43- if (FileExcluder::isAbsolutePath ($ path )) {
44- if (is_dir ($ path )) {
40+ foreach ($ newExcludePaths as $ key => $ paths ) {
41+ foreach ($ paths as $ path ) {
42+ if ($ path instanceof OptionalPath) {
4543 continue ;
4644 }
47- if (is_file ($ path )) {
45+ if (FileExcluder::isAbsolutePath ($ path )) {
46+ if (is_dir ($ path )) {
47+ continue ;
48+ }
49+ if (is_file ($ path )) {
50+ continue ;
51+ }
52+ }
53+ if (FileExcluder::isFnmatchPattern ($ path )) {
4854 continue ;
4955 }
50- }
51- if (FileExcluder::isFnmatchPattern ($ path )) {
52- continue ;
53- }
5456
55- $ errors [] = sprintf ('Path %s is neither a directory, nor a file path, nor a fnmatch pattern. ' , $ path );
57+ $ suggestOptional [$ key ][] = $ path ;
58+ $ errors [] = sprintf ('Path %s is neither a directory, nor a file path, nor a fnmatch pattern. ' , $ path );
59+ }
5660 }
5761 }
5862
59- $ newExcludePaths = [];
60- if (array_key_exists ('analyseAndScan ' , $ excludePaths )) {
61- $ newExcludePaths ['analyseAndScan ' ] = $ excludePaths ['analyseAndScan ' ];
62- }
63- if (array_key_exists ('analyse ' , $ excludePaths )) {
64- $ newExcludePaths ['analyse ' ] = $ excludePaths ['analyse ' ];
63+ if (count ($ errors ) !== 0 ) {
64+ throw new InvalidExcludePathsException ($ errors , $ suggestOptional );
6565 }
6666
6767 foreach ($ newExcludePaths as $ key => $ p ) {
@@ -72,12 +72,6 @@ public function loadConfiguration(): void
7272 }
7373
7474 $ builder ->parameters ['excludePaths ' ] = $ newExcludePaths ;
75-
76- if (count ($ errors ) === 0 ) {
77- return ;
78- }
79-
80- throw new InvalidExcludePathsException ($ errors );
8175 }
8276
8377}
0 commit comments