Skip to content

Commit 76464ee

Browse files
committed
Diagnose extension - where is PHPStan running from
1 parent db71f04 commit 76464ee

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

conf/config.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,8 @@ services:
21062106

21072107
phpstanDiagnoseExtension:
21082108
class: PHPStan\Diagnose\PHPStanDiagnoseExtension
2109+
arguments:
2110+
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
21092111
autowired: false
21102112

21112113
# Error formatters

src/Diagnose/PHPStanDiagnoseExtension.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@
22

33
namespace PHPStan\Diagnose;
44

5+
use Phar;
56
use PHPStan\Command\Output;
67
use PHPStan\ExtensionInstaller\GeneratedConfig;
78
use PHPStan\Internal\ComposerHelper;
89
use PHPStan\Php\PhpVersion;
910
use function class_exists;
1011
use function count;
12+
use function dirname;
13+
use function is_file;
1114
use function sprintf;
1215
use const PHP_VERSION_ID;
1316

1417
class PHPStanDiagnoseExtension implements DiagnoseExtension
1518
{
1619

17-
public function __construct(private PhpVersion $phpVersion)
20+
/**
21+
* @param string[] $composerAutoloaderProjectPaths
22+
*/
23+
public function __construct(
24+
private PhpVersion $phpVersion,
25+
private array $composerAutoloaderProjectPaths,
26+
)
1827
{
1928
}
2029

@@ -30,11 +39,25 @@ public function print(Output $output): void
3039
$this->phpVersion->getVersionString(),
3140
$this->phpVersion->getSourceLabel(),
3241
));
42+
$output->writeLineFormatted('');
43+
3344
$output->writeLineFormatted(sprintf(
3445
'<info>PHPStan version:</info> %s',
3546
ComposerHelper::getPhpStanVersion(),
3647
));
48+
$output->writeLineFormatted('<info>PHPStan running from:</info>');
49+
$pharRunning = Phar::running(false);
50+
if ($pharRunning !== '') {
51+
$output->writeLineFormatted(dirname($pharRunning));
52+
} else {
53+
if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) {
54+
$output->writeLineFormatted($_SERVER['argv'][0]);
55+
} else {
56+
$output->writeLineFormatted('Unknown');
57+
}
58+
}
3759
$output->writeLineFormatted('');
60+
3861
if (class_exists('PHPStan\ExtensionInstaller\GeneratedConfig')) {
3962
$output->writeLineFormatted('<info>Extension installer:</info>');
4063
if (count(GeneratedConfig::EXTENSIONS) === 0) {
@@ -47,6 +70,12 @@ public function print(Output $output): void
4770
$output->writeLineFormatted('<info>Extension installer:</info> Not installed');
4871
}
4972
$output->writeLineFormatted('');
73+
74+
$output->writeLineFormatted('<info>Discovered Composer project roots:</info>');
75+
foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) {
76+
$output->writeLineFormatted($composerAutoloaderProjectPath);
77+
}
78+
$output->writeLineFormatted('');
5079
}
5180

5281
}

0 commit comments

Comments
 (0)