Skip to content

Commit 2cc6cda

Browse files
committed
Fix and simplify discovering composer autoloader project path
1 parent f16d85a commit 2cc6cda

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

bin/phpstan

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,34 +92,30 @@ use Symfony\Component\Console\Helper\ProgressBar;
9292
require_once $autoloaderInWorkingDirectory;
9393
}
9494

95-
$autoloadProjectAutoloaderFile = function (string $file) use (&$composerAutoloaderProjectPaths): void {
96-
$path = dirname(__DIR__) . $file;
97-
if (!extension_loaded('phar')) {
95+
$path = dirname(__DIR__, 3) . '/autoload.php';
96+
if (!extension_loaded('phar')) {
97+
if (@is_file($path)) {
98+
$composerAutoloaderProjectPaths[] = dirname($path, 2);
99+
100+
require_once $path;
101+
}
102+
} else {
103+
$pharPath = \Phar::running(false);
104+
if ($pharPath === '') {
98105
if (@is_file($path)) {
99106
$composerAutoloaderProjectPaths[] = dirname($path, 2);
100107

101108
require_once $path;
102109
}
103110
} else {
104-
$pharPath = \Phar::running(false);
105-
if ($pharPath === '') {
106-
if (@is_file($path)) {
107-
$composerAutoloaderProjectPaths[] = dirname($path, 2);
108-
109-
require_once $path;
110-
}
111-
} else {
112-
$path = dirname($pharPath) . $file;
113-
if (@is_file($path)) {
114-
$composerAutoloaderProjectPaths[] = dirname($path, 2);
111+
$path = dirname($pharPath, 3) . '/autoload.php';
112+
if (@is_file($path)) {
113+
$composerAutoloaderProjectPaths[] = dirname($path, 2);
115114

116-
require_once $path;
117-
}
115+
require_once $path;
118116
}
119117
}
120-
};
121-
122-
$autoloadProjectAutoloaderFile('/../../autoload.php');
118+
}
123119

124120
/** @var array<callable>|false $autoloadFunctionsAfter */
125121
$autoloadFunctionsAfter = spl_autoload_functions();

0 commit comments

Comments
 (0)