diff --git a/conf/config.neon b/conf/config.neon index f5d21b7ee1..a27b16a518 100644 --- a/conf/config.neon +++ b/conf/config.neon @@ -2106,6 +2106,8 @@ services: phpstanDiagnoseExtension: class: PHPStan\Diagnose\PHPStanDiagnoseExtension + arguments: + composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths% autowired: false # Error formatters diff --git a/src/Diagnose/PHPStanDiagnoseExtension.php b/src/Diagnose/PHPStanDiagnoseExtension.php index 60ab2e5493..000f9aa0da 100644 --- a/src/Diagnose/PHPStanDiagnoseExtension.php +++ b/src/Diagnose/PHPStanDiagnoseExtension.php @@ -2,19 +2,28 @@ namespace PHPStan\Diagnose; +use Phar; use PHPStan\Command\Output; use PHPStan\ExtensionInstaller\GeneratedConfig; use PHPStan\Internal\ComposerHelper; use PHPStan\Php\PhpVersion; use function class_exists; use function count; +use function dirname; +use function is_file; use function sprintf; use const PHP_VERSION_ID; class PHPStanDiagnoseExtension implements DiagnoseExtension { - public function __construct(private PhpVersion $phpVersion) + /** + * @param string[] $composerAutoloaderProjectPaths + */ + public function __construct( + private PhpVersion $phpVersion, + private array $composerAutoloaderProjectPaths, + ) { } @@ -30,11 +39,25 @@ public function print(Output $output): void $this->phpVersion->getVersionString(), $this->phpVersion->getSourceLabel(), )); + $output->writeLineFormatted(''); + $output->writeLineFormatted(sprintf( 'PHPStan version: %s', ComposerHelper::getPhpStanVersion(), )); + $output->writeLineFormatted('PHPStan running from:'); + $pharRunning = Phar::running(false); + if ($pharRunning !== '') { + $output->writeLineFormatted(dirname($pharRunning)); + } else { + if (isset($_SERVER['argv'][0]) && is_file($_SERVER['argv'][0])) { + $output->writeLineFormatted($_SERVER['argv'][0]); + } else { + $output->writeLineFormatted('Unknown'); + } + } $output->writeLineFormatted(''); + if (class_exists('PHPStan\ExtensionInstaller\GeneratedConfig')) { $output->writeLineFormatted('Extension installer:'); if (count(GeneratedConfig::EXTENSIONS) === 0) { @@ -47,6 +70,12 @@ public function print(Output $output): void $output->writeLineFormatted('Extension installer: Not installed'); } $output->writeLineFormatted(''); + + $output->writeLineFormatted('Discovered Composer project roots:'); + foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) { + $output->writeLineFormatted($composerAutoloaderProjectPath); + } + $output->writeLineFormatted(''); } }