Skip to content

Commit bff85e2

Browse files
committed
Fix FuzzyRelativePathHelper for directories ending in .php
1 parent dc1688e commit bff85e2

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/File/FuzzyRelativePathHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ public function __construct(
7070
/** @var string[] $pathArray */
7171
$pathArray = explode($directorySeparator, $path);
7272
$pathTempParts = [];
73+
$pathArraySize = count($pathArray);
7374
foreach ($pathArray as $i => $pathPart) {
74-
if (str_ends_with($pathPart, '.php')) {
75+
if ($i === $pathArraySize - 1 && str_ends_with($pathPart, '.php')) {
7576
continue;
7677
}
7778
if (!isset($pathToTrimArray[$i])) {

tests/PHPStan/File/RelativePathHelperTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,40 @@ public function dataGetRelativePath(): array
142142
'/usr/app/src/analyzed.php',
143143
'/usr/app/src/analyzed.php',
144144
],
145+
[
146+
'/Users/ondrej/Downloads/phpstan-wtf/normal.php',
147+
[
148+
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/src',
149+
],
150+
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/src/index.php',
151+
'index.php',
152+
],
153+
[
154+
'/Users/ondrej/Downloads/phpstan-wtf/normal',
155+
[
156+
'/Users/ondrej/Downloads/phpstan-wtf/normal/src',
157+
],
158+
'/Users/ondrej/Downloads/phpstan-wtf/normal/src/index.php',
159+
'index.php',
160+
],
161+
[
162+
'/Users/ondrej/Downloads/phpstan-wtf/normal.php',
163+
[
164+
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/src',
165+
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/tests',
166+
],
167+
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/src/index.php',
168+
'src/index.php',
169+
],
170+
[
171+
'/Users/ondrej/Downloads/phpstan-wtf/normal',
172+
[
173+
'/Users/ondrej/Downloads/phpstan-wtf/normal/src',
174+
'/Users/ondrej/Downloads/phpstan-wtf/normal/tests',
175+
],
176+
'/Users/ondrej/Downloads/phpstan-wtf/normal/src/index.php',
177+
'src/index.php',
178+
],
145179
];
146180
}
147181

0 commit comments

Comments
 (0)