From 098fb9416779240fab9b2dea1ee730da69668014 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 23 Sep 2024 13:04:28 +0200 Subject: [PATCH] Fix including relative path --- src/Rules/Keywords/RequireFileExistsRule.php | 3 +-- tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php | 5 +++++ tests/PHPStan/Rules/Keywords/data/bug-11738-included.php | 2 ++ tests/PHPStan/Rules/Keywords/data/bug-11738/bug-11738.php | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 tests/PHPStan/Rules/Keywords/data/bug-11738-included.php create mode 100644 tests/PHPStan/Rules/Keywords/data/bug-11738/bug-11738.php diff --git a/src/Rules/Keywords/RequireFileExistsRule.php b/src/Rules/Keywords/RequireFileExistsRule.php index f2a9af9989b..8ccf92e3dfc 100644 --- a/src/Rules/Keywords/RequireFileExistsRule.php +++ b/src/Rules/Keywords/RequireFileExistsRule.php @@ -77,8 +77,7 @@ private function doesFileExist(string $path, Scope $scope): bool private function doesFileExistForDirectory(string $path, string $workingDirectory): bool { $fileHelper = new FileHelper($workingDirectory); - $normalisedPath = $fileHelper->normalizePath($path); - $absolutePath = $fileHelper->absolutizePath($normalisedPath); + $absolutePath = $fileHelper->absolutizePath($path); return is_file($absolutePath); } diff --git a/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php b/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php index ee96f404662..6bd3e1dfd72 100644 --- a/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php +++ b/tests/PHPStan/Rules/Keywords/RequireFileExistsRuleTest.php @@ -116,4 +116,9 @@ public function testRelativePathWithSameWorkingDirectory(): void $this->analyse([__DIR__ . '/data/require-file-relative-path.php'], []); } + public function testBug11738(): void + { + $this->analyse([__DIR__ . '/data/bug-11738/bug-11738.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Keywords/data/bug-11738-included.php b/tests/PHPStan/Rules/Keywords/data/bug-11738-included.php new file mode 100644 index 00000000000..a4abe2dafcb --- /dev/null +++ b/tests/PHPStan/Rules/Keywords/data/bug-11738-included.php @@ -0,0 +1,2 @@ +