Skip to content

Commit 326efe1

Browse files
committed
diagnose: print composer.json required php version
1 parent b585dfd commit 326efe1

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Diagnose/PHPStanDiagnoseExtension.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ public function print(Output $output): void
4848
'<info>PHP runtime version:</info> %s',
4949
$phpRuntimeVersion->getVersionString(),
5050
));
51+
52+
$composerPhpVersion = $this->getComposerRequireVersion();
53+
if ($composerPhpVersion !== null) {
54+
$output->writeLineFormatted(sprintf(
55+
'<info>PHP composer.json required version:</info> %s',
56+
$composerPhpVersion,
57+
));
58+
}
59+
5160
$output->writeLineFormatted(sprintf(
5261
'<info>PHP version for analysis:</info> %s (from %s)',
5362
$this->phpVersion->getVersionString(),
@@ -166,4 +175,22 @@ public function print(Output $output): void
166175
$output->writeLineFormatted('');
167176
}
168177

178+
private function getComposerRequireVersion(): ?string
179+
{
180+
$composerPhpVersion = null;
181+
182+
if (count($this->composerAutoloaderProjectPaths) > 0) {
183+
$composer = ComposerHelper::getComposerConfig(end($this->composerAutoloaderProjectPaths));
184+
if ($composer !== null) {
185+
$requiredVersion = $composer['require']['php'] ?? null;
186+
187+
if (is_string($requiredVersion)) {
188+
$composerPhpVersion = $requiredVersion;
189+
}
190+
}
191+
}
192+
193+
return $composerPhpVersion;
194+
}
195+
169196
}

0 commit comments

Comments
 (0)