44
55use PHPStan \File \FileHelper ;
66use function array_fill_keys ;
7+ use function array_map ;
78use function array_slice ;
89use function count ;
910use function explode ;
1011use function implode ;
1112use function is_link ;
1213use function realpath ;
1314use function str_contains ;
15+ use function strtolower ;
1416use const DIRECTORY_SEPARATOR ;
17+ use const PHP_OS_FAMILY ;
1518
1619final class PathRoutingParser implements Parser
1720{
1821
1922 /** @var bool[] filePath(string) => bool(true) */
2023 private array $ analysedFiles = [];
2124
25+ private bool $ caseInsensitiveFilesystem ;
26+
2227 public function __construct (
2328 private FileHelper $ fileHelper ,
2429 private Parser $ currentPhpVersionRichParser ,
2530 private Parser $ currentPhpVersionSimpleParser ,
2631 private Parser $ php8Parser ,
2732 )
2833 {
34+ $ this ->caseInsensitiveFilesystem = PHP_OS_FAMILY === 'Darwin ' ;
2935 }
3036
3137 /**
3238 * @param string[] $files
3339 */
3440 public function setAnalysedFiles (array $ files ): void
3541 {
42+ if ($ this ->caseInsensitiveFilesystem ) {
43+ $ files = array_map (static fn (string $ file ): string => strtolower ($ file ), $ files );
44+ }
3645 $ this ->analysedFiles = array_fill_keys ($ files , true );
3746 }
3847
48+ private function isInAnalyzedFiles (string $ file ): bool
49+ {
50+ if ($ this ->caseInsensitiveFilesystem ) {
51+ $ file = strtolower ($ file );
52+ }
53+
54+ return isset ($ this ->analysedFiles [$ file ]);
55+ }
56+
3957 public function parseFile (string $ file ): array
4058 {
4159 $ normalizedPath = $ this ->fileHelper ->normalizePath ($ file , '/ ' );
@@ -47,7 +65,7 @@ public function parseFile(string $file): array
4765 }
4866
4967 $ file = $ this ->fileHelper ->normalizePath ($ file );
50- if (!isset ( $ this ->analysedFiles [ $ file] )) {
68+ if (!$ this ->isInAnalyzedFiles ( $ file )) {
5169 // check symlinked file that still might be in analysedFiles
5270 $ pathParts = explode (DIRECTORY_SEPARATOR , $ file );
5371 for ($ i = count ($ pathParts ); $ i > 1 ; $ i --) {
@@ -59,7 +77,7 @@ public function parseFile(string $file): array
5977 $ realFilePath = realpath ($ file );
6078 if ($ realFilePath !== false ) {
6179 $ normalizedRealFilePath = $ this ->fileHelper ->normalizePath ($ realFilePath );
62- if (isset ( $ this ->analysedFiles [ $ normalizedRealFilePath] )) {
80+ if ($ this ->isInAnalyzedFiles ( $ normalizedRealFilePath )) {
6381 return $ this ->currentPhpVersionRichParser ->parseFile ($ file );
6482 }
6583 }
0 commit comments