Skip to content

Commit 856dd8e

Browse files
committed
separate min/max composer version
1 parent 836ef1c commit 856dd8e

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

conf/config.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ parameters:
7070
maximumNumberOfProcesses: 32
7171
minimumNumberOfJobsPerProcess: 2
7272
buffer: 134217728 # 128 MB
73-
phpVersion: null
73+
phpVersion:
74+
min: 80303
75+
max: 80104
7476
polluteScopeWithLoopInitialAssignments: true
7577
polluteScopeWithAlwaysIterableForeach: true
7678
polluteScopeWithBlock: true

src/Diagnose/PHPStanDiagnoseExtension.php

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PHPStan\ExtensionInstaller\GeneratedConfig;
88
use PHPStan\File\FileHelper;
99
use PHPStan\Internal\ComposerHelper;
10+
use PHPStan\Php\ComposerPhpVersionFactory;
1011
use PHPStan\Php\PhpVersion;
1112
use ReflectionClass;
1213
use function array_key_exists;
@@ -42,6 +43,7 @@ public function __construct(
4243
private FileHelper $fileHelper,
4344
private array $composerAutoloaderProjectPaths,
4445
private array $allConfigFiles,
46+
private ComposerPhpVersionFactory $composerPhpVersionFactory,
4547
)
4648
{
4749
}
@@ -54,12 +56,21 @@ public function print(Output $output): void
5456
$phpRuntimeVersion->getVersionString(),
5557
));
5658

57-
$composerPhpVersion = $this->getComposerRequireVersion();
58-
if ($composerPhpVersion !== null) {
59-
$output->writeLineFormatted(sprintf(
60-
'<info>PHP composer.json required version:</info> %s',
61-
$composerPhpVersion,
62-
));
59+
$minComposerPhpVersion = $this->composerPhpVersionFactory->getMinVersion();
60+
$maxComposerPhpVersion = $this->composerPhpVersionFactory->getMaxVersion();
61+
if ($minComposerPhpVersion !== null && $maxComposerPhpVersion !== null) {
62+
if ($minComposerPhpVersion->getVersionId() === $maxComposerPhpVersion->getVersionId()) {
63+
$output->writeLineFormatted(sprintf(
64+
'<info>PHP composer.json required version:</info> %s',
65+
$minComposerPhpVersion->getVersionString(),
66+
));
67+
} else {
68+
$output->writeLineFormatted(sprintf(
69+
'<info>PHP composer.json required version:</info> %s-%s',
70+
$minComposerPhpVersion->getVersionString(),
71+
$maxComposerPhpVersion->getVersionString(),
72+
));
73+
}
6374
}
6475

6576
if (
@@ -196,22 +207,4 @@ public function print(Output $output): void
196207
$output->writeLineFormatted('');
197208
}
198209

199-
private function getComposerRequireVersion(): ?string
200-
{
201-
$composerPhpVersion = null;
202-
203-
if (count($this->composerAutoloaderProjectPaths) > 0) {
204-
$composer = ComposerHelper::getComposerConfig(end($this->composerAutoloaderProjectPaths));
205-
if ($composer !== null) {
206-
$requiredVersion = $composer['require']['php'] ?? null;
207-
208-
if (is_string($requiredVersion)) {
209-
$composerPhpVersion = $requiredVersion;
210-
}
211-
}
212-
}
213-
214-
return $composerPhpVersion;
215-
}
216-
217210
}

0 commit comments

Comments
 (0)