File tree Expand file tree Collapse file tree 3 files changed +48
-6
lines changed
Expand file tree Collapse file tree 3 files changed +48
-6
lines changed Original file line number Diff line number Diff line change 22
33namespace PHPStan \Analyser ;
44
5+ use PHPStan \File \FilesystemHelper ;
56use function array_fill_keys ;
67use function array_map ;
78use function strtolower ;
8- use const PHP_OS_FAMILY ;
99
1010final class AnalysedFilesResolver
1111{
1212
1313 /** @var bool[] filePath(string) => bool(true) */
1414 private array $ analysedFiles ;
1515
16- private bool $ caseInsensitiveFilesystem ;
17-
1816 /**
1917 * @param string[] $files
2018 */
2119 public function __construct (array $ files = [])
2220 {
23- $ this ->caseInsensitiveFilesystem = PHP_OS_FAMILY === 'Windows ' || PHP_OS_FAMILY === 'Darwin ' ;
21+ if ($ files === []) {
22+ return ;
23+ }
24+
2425 $ this ->setAnalysedFiles ($ files );
2526 }
2627
@@ -29,15 +30,15 @@ public function __construct(array $files = [])
2930 */
3031 public function setAnalysedFiles (array $ files ): void
3132 {
32- if ($ this -> caseInsensitiveFilesystem ) {
33+ if (FilesystemHelper:: isCaseSensitive () === false ) {
3334 $ files = array_map (static fn (string $ file ): string => strtolower ($ file ), $ files );
3435 }
3536 $ this ->analysedFiles = array_fill_keys ($ files , true );
3637 }
3738
3839 public function isInAnalyzedFiles (string $ file ): bool
3940 {
40- if ($ this -> caseInsensitiveFilesystem ) {
41+ if (FilesystemHelper:: isCaseSensitive () === false ) {
4142 $ file = strtolower ($ file );
4243 }
4344
Original file line number Diff line number Diff line change 2424use PHPStan \BetterReflection \SourceLocator \Type \SourceLocator ;
2525use PHPStan \Command \CommandHelper ;
2626use PHPStan \File \FileHelper ;
27+ use PHPStan \File \FilesystemHelper ;
2728use PHPStan \Node \Printer \Printer ;
2829use PHPStan \Php \PhpVersion ;
2930use PHPStan \Reflection \PhpVersionStaticAccessor ;
@@ -190,6 +191,7 @@ public static function postInitializeContainer(Container $container): void
190191 $ container ->getService ('typeSpecifier ' );
191192
192193 BleedingEdgeToggle::setBleedingEdge ($ container ->getParameter ('featureToggles ' )['bleedingEdge ' ]);
194+ FilesystemHelper::checkIsCaseSensitive ($ container ->getParameter ('tmpDir ' ));
193195 }
194196
195197 public function getCurrentWorkingDirectory (): string
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \File ;
4+
5+ use function file_get_contents ;
6+ use function file_put_contents ;
7+ use function strtoupper ;
8+
9+ final class FilesystemHelper
10+ {
11+
12+ private const SIGNATURE_CONTENT = 'PHPStan case-sensitivity check ' ;
13+
14+ private static ?bool $ isCaseSensitive = null ;
15+
16+ public static function isCaseSensitive (): bool
17+ {
18+ return self ::$ isCaseSensitive ;
19+ }
20+
21+ public static function checkIsCaseSensitive (string $ tmpDir ): void
22+ {
23+ if (self ::$ isCaseSensitive !== null ) {
24+ return ;
25+ }
26+
27+ $ fileName = 'test-file-system-case-sensitivity.tmp ' ;
28+ @file_put_contents ($ tmpDir . '/ ' . $ fileName , self ::SIGNATURE_CONTENT );
29+
30+ if (@file_get_contents ($ tmpDir . '/ ' . strtoupper ($ fileName )) === self ::SIGNATURE_CONTENT ) {
31+ self ::$ isCaseSensitive = false ;
32+
33+ return ;
34+ }
35+
36+ self ::$ isCaseSensitive = true ;
37+ }
38+
39+ }
You can’t perform that action at this time.
0 commit comments