Skip to content

More details php version information in diagnose #3609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,7 @@ services:
arguments:
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
allConfigFiles: %allConfigFiles%
configPhpVersion: %phpVersion%
autowired: false

# Error formatters

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix_Resolve_Complete

Expand Down
49 changes: 44 additions & 5 deletions src/Diagnose/PHPStanDiagnoseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PHPStan\ExtensionInstaller\GeneratedConfig;
use PHPStan\File\FileHelper;
use PHPStan\Internal\ComposerHelper;
use PHPStan\Php\ComposerPhpVersionFactory;
use PHPStan\Php\PhpVersion;
use ReflectionClass;
use function array_key_exists;
Expand All @@ -17,6 +18,7 @@
use function explode;
use function implode;
use function in_array;
use function is_array;
use function is_file;
use function is_readable;
use function sprintf;
Expand All @@ -29,14 +31,17 @@ final class PHPStanDiagnoseExtension implements DiagnoseExtension
{

/**
* @param int|array{min: int, max: int}|null $configPhpVersion
* @param string[] $composerAutoloaderProjectPaths
* @param string [] $allConfigFiles
*/
public function __construct(
private PhpVersion $phpVersion,
private int|array|null $configPhpVersion,
private FileHelper $fileHelper,
private array $composerAutoloaderProjectPaths,
private array $allConfigFiles,
private ComposerPhpVersionFactory $composerPhpVersionFactory,
)
{
}
Expand All @@ -48,11 +53,45 @@ public function print(Output $output): void
'<info>PHP runtime version:</info> %s',
$phpRuntimeVersion->getVersionString(),
));
$output->writeLineFormatted(sprintf(
'<info>PHP version for analysis:</info> %s (from %s)',
$this->phpVersion->getVersionString(),
$this->phpVersion->getSourceLabel(),
));

if (
$this->phpVersion->getSource() === PhpVersion::SOURCE_CONFIG
&& is_array($this->configPhpVersion)
) {
$minVersion = new PhpVersion($this->configPhpVersion['min']);
$maxVersion = new PhpVersion($this->configPhpVersion['max']);

$output->writeLineFormatted(sprintf(
'<info>PHP version for analysis:</info> %s-%s (from %s)',
$minVersion->getVersionString(),
$maxVersion->getVersionString(),
$this->phpVersion->getSourceLabel(),
));

} else {
$minComposerPhpVersion = $this->composerPhpVersionFactory->getMinVersion();
$maxComposerPhpVersion = $this->composerPhpVersionFactory->getMaxVersion();
if ($minComposerPhpVersion !== null && $maxComposerPhpVersion !== null) {
if ($minComposerPhpVersion->getVersionId() !== $maxComposerPhpVersion->getVersionId()) {
$output->writeLineFormatted(sprintf(
'<info>PHP composer.json required version:</info> %s-%s',
$minComposerPhpVersion->getVersionString(),
$maxComposerPhpVersion->getVersionString(),
));
} else {
$output->writeLineFormatted(sprintf(
'<info>PHP composer.json required version:</info> %s',
$minComposerPhpVersion->getVersionString(),
));
}
}

$output->writeLineFormatted(sprintf(
'<info>PHP version for analysis:</info> %s (from %s)',
$this->phpVersion->getVersionString(),
$this->phpVersion->getSourceLabel(),
));
}
$output->writeLineFormatted('');

$output->writeLineFormatted(sprintf(
Expand Down
8 changes: 8 additions & 0 deletions src/Php/PhpVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public function __construct(private int $versionId, private int $source = self::
{
}

/**
* @return self::SOURCE_*
*/
public function getSource(): int
{
return $this->source;
}

public function getSourceLabel(): string
{
switch ($this->source) {
Expand Down
Loading