Skip to content

Commit

Permalink
Fix FuzzyRelativePathHelper for directories ending in .php
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 7, 2022
1 parent dc1688e commit bff85e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/File/FuzzyRelativePathHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public function __construct(
/** @var string[] $pathArray */
$pathArray = explode($directorySeparator, $path);
$pathTempParts = [];
$pathArraySize = count($pathArray);
foreach ($pathArray as $i => $pathPart) {
if (str_ends_with($pathPart, '.php')) {
if ($i === $pathArraySize - 1 && str_ends_with($pathPart, '.php')) {
continue;
}
if (!isset($pathToTrimArray[$i])) {
Expand Down
34 changes: 34 additions & 0 deletions tests/PHPStan/File/RelativePathHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,40 @@ public function dataGetRelativePath(): array
'/usr/app/src/analyzed.php',
'/usr/app/src/analyzed.php',
],
[
'/Users/ondrej/Downloads/phpstan-wtf/normal.php',
[
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/src',
],
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/src/index.php',
'index.php',
],
[
'/Users/ondrej/Downloads/phpstan-wtf/normal',
[
'/Users/ondrej/Downloads/phpstan-wtf/normal/src',
],
'/Users/ondrej/Downloads/phpstan-wtf/normal/src/index.php',
'index.php',
],
[
'/Users/ondrej/Downloads/phpstan-wtf/normal.php',
[
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/src',
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/tests',
],
'/Users/ondrej/Downloads/phpstan-wtf/normal.php/src/index.php',
'src/index.php',
],
[
'/Users/ondrej/Downloads/phpstan-wtf/normal',
[
'/Users/ondrej/Downloads/phpstan-wtf/normal/src',
'/Users/ondrej/Downloads/phpstan-wtf/normal/tests',
],
'/Users/ondrej/Downloads/phpstan-wtf/normal/src/index.php',
'src/index.php',
],
];
}

Expand Down

0 comments on commit bff85e2

Please sign in to comment.