Skip to content

Commit 6d0601a

Browse files
committed
Fix composerAutoloaderProjectPaths array so that the items always refer to dir with composer.json in it
1 parent d1f76fc commit 6d0601a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

bin/phpstan

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ use Symfony\Component\Console\Helper\ProgressBar;
2020

2121
$devOrPharLoader = require_once __DIR__ . '/../vendor/autoload.php';
2222
require_once __DIR__ . '/../preload.php';
23+
$composerJsonPath = ComposerHelper::getComposerJsonPath(getcwd());
2324
$composer = ComposerHelper::getComposerConfig(getcwd());
2425

2526
if ($composer !== null) {
2627
$vendorDirectory = ComposerHelper::getVendorDirFromComposerConfig(getcwd(), $composer);
2728
} else {
28-
$vendorDirectory = getcwd() . '/' . 'vendor';
29+
$vendorDirectory = getcwd() . '/vendor';
2930
}
3031
$devOrPharLoader->unregister();
3132

@@ -43,7 +44,9 @@ use Symfony\Component\Console\Helper\ProgressBar;
4344
$autoloadFunctionsBefore = spl_autoload_functions();
4445

4546
if (@is_file($autoloaderInWorkingDirectory)) {
46-
$composerAutoloaderProjectPaths[] = dirname($autoloaderInWorkingDirectory, 2);
47+
if ($composerJsonPath !== null) {
48+
$composerAutoloaderProjectPaths[] = dirname($composerJsonPath);
49+
}
4750

4851
require_once $autoloaderInWorkingDirectory;
4952
}

src/Internal/ComposerHelper.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@ public static function getComposerConfig(string $root): ?array
2626
{
2727
$composerJsonPath = self::getComposerJsonPath($root);
2828

29-
if (!is_file($composerJsonPath)) {
30-
return null;
31-
}
32-
3329
try {
3430
$composerJsonContents = FileReader::read($composerJsonPath);
3531

@@ -39,13 +35,18 @@ public static function getComposerConfig(string $root): ?array
3935
}
4036
}
4137

42-
private static function getComposerJsonPath(string $root): string
38+
public static function getComposerJsonPath(string $root): ?string
4339
{
4440
$envComposer = getenv('COMPOSER');
4541
$fileName = is_string($envComposer) ? $envComposer : 'composer.json';
4642
$fileName = basename(trim($fileName));
4743

48-
return $root . '/' . $fileName;
44+
$path = $root . '/' . $fileName;
45+
if (!is_file($path)) {
46+
return null;
47+
}
48+
49+
return $path;
4950
}
5051

5152
/**

0 commit comments

Comments
 (0)