Skip to content

Commit d00f0de

Browse files
authored
Optimize path related utils on windows
1 parent 63da9bc commit d00f0de

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/File/FileHelper.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use function rtrim;
1111
use function str_replace;
1212
use function str_starts_with;
13+
use function strlen;
1314
use function strpos;
1415
use function substr;
1516
use function trim;
@@ -52,7 +53,14 @@ public function absolutizePath(string $path): string
5253
/** @api */
5354
public function normalizePath(string $originalPath, string $directorySeparator = DIRECTORY_SEPARATOR): string
5455
{
55-
$isLocalPath = $originalPath !== '' && $originalPath[0] === '/';
56+
$isLocalPath = false;
57+
if ($originalPath !== '') {
58+
if ($originalPath[0] === '/') {
59+
$isLocalPath = true;
60+
} elseif (strlen($originalPath) >= 3 && $originalPath[1] === ':' && $originalPath[2] === '\\') { // e.g. C:\
61+
$isLocalPath = true;
62+
}
63+
}
5664

5765
$matches = null;
5866
if (!$isLocalPath) {

src/Type/FileTypeMapper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ public function getResolvedPhpDoc(
7676
string $docComment,
7777
): ResolvedPhpDocBlock
7878
{
79-
if ($fileName !== null) {
80-
$fileName = $this->fileHelper->normalizePath($fileName);
81-
}
82-
8379
if ($className === null && $traitName !== null) {
8480
throw new ShouldNotHappenException();
8581
}
@@ -88,6 +84,10 @@ public function getResolvedPhpDoc(
8884
return ResolvedPhpDocBlock::createEmpty();
8985
}
9086

87+
if ($fileName !== null) {
88+
$fileName = $this->fileHelper->normalizePath($fileName);
89+
}
90+
9191
$nameScopeKey = $this->getNameScopeKey($fileName, $className, $traitName, $functionName);
9292
$phpDocKey = md5(sprintf('%s-%s', $nameScopeKey, $docComment));
9393
if (isset($this->resolvedPhpDocBlockCache[$phpDocKey])) {

0 commit comments

Comments
 (0)