From 2cc6cda6969a63267e70c2074efa0477b69c9083 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Sun, 14 Jul 2024 14:13:04 +0200 Subject: [PATCH] Fix and simplify discovering composer autoloader project path --- bin/phpstan | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/bin/phpstan b/bin/phpstan index a8c0fd8dd0..dd930fcc8f 100755 --- a/bin/phpstan +++ b/bin/phpstan @@ -92,34 +92,30 @@ use Symfony\Component\Console\Helper\ProgressBar; require_once $autoloaderInWorkingDirectory; } - $autoloadProjectAutoloaderFile = function (string $file) use (&$composerAutoloaderProjectPaths): void { - $path = dirname(__DIR__) . $file; - if (!extension_loaded('phar')) { + $path = dirname(__DIR__, 3) . '/autoload.php'; + if (!extension_loaded('phar')) { + if (@is_file($path)) { + $composerAutoloaderProjectPaths[] = dirname($path, 2); + + require_once $path; + } + } else { + $pharPath = \Phar::running(false); + if ($pharPath === '') { if (@is_file($path)) { $composerAutoloaderProjectPaths[] = dirname($path, 2); require_once $path; } } else { - $pharPath = \Phar::running(false); - if ($pharPath === '') { - if (@is_file($path)) { - $composerAutoloaderProjectPaths[] = dirname($path, 2); - - require_once $path; - } - } else { - $path = dirname($pharPath) . $file; - if (@is_file($path)) { - $composerAutoloaderProjectPaths[] = dirname($path, 2); + $path = dirname($pharPath, 3) . '/autoload.php'; + if (@is_file($path)) { + $composerAutoloaderProjectPaths[] = dirname($path, 2); - require_once $path; - } + require_once $path; } } - }; - - $autoloadProjectAutoloaderFile('/../../autoload.php'); + } /** @var array|false $autoloadFunctionsAfter */ $autoloadFunctionsAfter = spl_autoload_functions();