File tree 3 files changed +48
-6
lines changed
3 files changed +48
-6
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace PHPStan \Analyser ;
4
4
5
+ use PHPStan \File \FilesystemHelper ;
5
6
use function array_fill_keys ;
6
7
use function array_map ;
7
8
use function strtolower ;
8
- use const PHP_OS_FAMILY ;
9
9
10
10
final class AnalysedFilesResolver
11
11
{
12
12
13
13
/** @var bool[] filePath(string) => bool(true) */
14
14
private array $ analysedFiles ;
15
15
16
- private bool $ caseInsensitiveFilesystem ;
17
-
18
16
/**
19
17
* @param string[] $files
20
18
*/
21
19
public function __construct (array $ files = [])
22
20
{
23
- $ this ->caseInsensitiveFilesystem = PHP_OS_FAMILY === 'Windows ' || PHP_OS_FAMILY === 'Darwin ' ;
21
+ if ($ files === []) {
22
+ return ;
23
+ }
24
+
24
25
$ this ->setAnalysedFiles ($ files );
25
26
}
26
27
@@ -29,15 +30,15 @@ public function __construct(array $files = [])
29
30
*/
30
31
public function setAnalysedFiles (array $ files ): void
31
32
{
32
- if ($ this -> caseInsensitiveFilesystem ) {
33
+ if (FilesystemHelper:: isCaseSensitive () === false ) {
33
34
$ files = array_map (static fn (string $ file ): string => strtolower ($ file ), $ files );
34
35
}
35
36
$ this ->analysedFiles = array_fill_keys ($ files , true );
36
37
}
37
38
38
39
public function isInAnalyzedFiles (string $ file ): bool
39
40
{
40
- if ($ this -> caseInsensitiveFilesystem ) {
41
+ if (FilesystemHelper:: isCaseSensitive () === false ) {
41
42
$ file = strtolower ($ file );
42
43
}
43
44
Original file line number Diff line number Diff line change 24
24
use PHPStan \BetterReflection \SourceLocator \Type \SourceLocator ;
25
25
use PHPStan \Command \CommandHelper ;
26
26
use PHPStan \File \FileHelper ;
27
+ use PHPStan \File \FilesystemHelper ;
27
28
use PHPStan \Node \Printer \Printer ;
28
29
use PHPStan \Php \PhpVersion ;
29
30
use PHPStan \Reflection \PhpVersionStaticAccessor ;
@@ -190,6 +191,7 @@ public static function postInitializeContainer(Container $container): void
190
191
$ container ->getService ('typeSpecifier ' );
191
192
192
193
BleedingEdgeToggle::setBleedingEdge ($ container ->getParameter ('featureToggles ' )['bleedingEdge ' ]);
194
+ FilesystemHelper::checkIsCaseSensitive ($ container ->getParameter ('tmpDir ' ));
193
195
}
194
196
195
197
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