From 06b218f8dd5bb4c79782488f38b0651ae41dbf41 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Wed, 4 Sep 2024 08:18:02 +0200 Subject: [PATCH] Fix case where installed path is symlink One can install packages from a local path via composers repositories type "path". Those are typically symlinks which were not resolved. We therefore add a realpath() call, but falling back to old behavior if it didn't resolve. That way we keep independent of realpath() as requested by the inline comment. Resolves: https://github.com/phpactor/phpactor/issues/2727 --- lib/Adapter/Composer/ComposerFileToClass.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Adapter/Composer/ComposerFileToClass.php b/lib/Adapter/Composer/ComposerFileToClass.php index f688627c..9fdb6f10 100644 --- a/lib/Adapter/Composer/ComposerFileToClass.php +++ b/lib/Adapter/Composer/ComposerFileToClass.php @@ -77,11 +77,11 @@ private function populateCandidates(FilePath $filePath, array $prefixes) $pathPrefixes = (array) $pathPrefixes; // remove any relativeness from the paths - // - // TODO: realpath will return void if the path does not exist - // we should not depend on the file path existing. + // we should not depend on the file path existing. $pathPrefixes = array_map(function ($pathPrefix) { - return Path::canonicalize($pathPrefix); + $canonicalizedPath = Path::canonicalize($pathPrefix); + $realPath = realpath($canonicalizedPath); + return $realPath ?: $canonicalizedPath; }, $pathPrefixes); foreach ($pathPrefixes as $pathPrefix) {