Skip to content

Commit 23a7403

Browse files
committed
fix PathRoutingParser
1 parent 683f3a8 commit 23a7403

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/Parser/PathRoutingParser.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,56 @@
44

55
use PHPStan\File\FileHelper;
66
use function array_fill_keys;
7+
use function array_map;
78
use function array_slice;
89
use function count;
910
use function explode;
1011
use function implode;
1112
use function is_link;
1213
use function realpath;
1314
use function str_contains;
15+
use function strtolower;
1416
use const DIRECTORY_SEPARATOR;
17+
use const PHP_OS_FAMILY;
1518

1619
final 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

Comments
 (0)