Skip to content

Commit 4df0082

Browse files
committed
Refactor canonicalizePath method to improve clarity and performance; remove outdated docblock and optimize array checks
1 parent 18d77b1 commit 4df0082

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

src/Internal/PathMatcher.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ public static function normalizePath(string|false|null $path): string
6464
return str_replace('\\', '/', $path);
6565
}
6666

67-
/**
68-
* Resolves dot-dot (..) relative segments in a path without hitting the disk.
69-
*/
7067
public static function canonicalizePath(string $path): string
7168
{
7269
$path = str_replace('\\', '/', $path);
@@ -79,14 +76,15 @@ public static function canonicalizePath(string $path): string
7976

8077
foreach ($parts as $part) {
8178
if ($part === '.' || $part === '') {
82-
if ($part === '' && empty($absolutes)) {
79+
if ($part === '' && \count($absolutes) === 0) {
8380
$absolutes[] = '';
8481
}
82+
8583
continue;
8684
}
8785

8886
if ($part === '..') {
89-
if (! empty($absolutes) && end($absolutes) !== '..') {
87+
if (\count($absolutes) > 0 && end($absolutes) !== '..') {
9088
array_pop($absolutes);
9189
} else {
9290
$absolutes[] = '..';

0 commit comments

Comments
 (0)