Skip to content

Commit 625bc7e

Browse files
authored
Fix platform version resolution, use require first (#5555)
* add fix for platofmr version * fix test
1 parent 037153b commit 625bc7e

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

rules/Php80/Rector/Class_/AnnotationToAttributeRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
2525
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
2626
use Rector\Contract\Rector\ConfigurableRectorInterface;
27+
use Rector\Exception\Configuration\InvalidConfigurationException;
2728
use Rector\Naming\Naming\UseImportsResolver;
2829
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
2930
use Rector\Php80\NodeFactory\AttrGroupsFactory;
@@ -33,7 +34,6 @@
3334
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
3435
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
3536
use Rector\Rector\AbstractRector;
36-
use Rector\Exception\Configuration\InvalidConfigurationException;
3737
use Rector\ValueObject\PhpVersionFeature;
3838
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
3939
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;

src/Php/PhpVersionResolver/ProjectComposerJsonPhpVersionResolver.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ public static function resolve(string $composerJson): ?int
2828
$composerJsonContents = FileSystem::read($composerJson);
2929
$projectComposerJson = Json::decode($composerJsonContents, Json::FORCE_ARRAY);
3030

31+
// give this one a priority, as more generic one
32+
$requirePhpVersion = $projectComposerJson['require']['php'] ?? null;
33+
if ($requirePhpVersion !== null) {
34+
self::$cachedPhpVersions[$composerJson] = self::createIntVersionFromComposerVersion($requirePhpVersion);
35+
return self::$cachedPhpVersions[$composerJson];
36+
}
37+
3138
// see https://getcomposer.org/doc/06-config.md#platform
3239
$platformPhp = $projectComposerJson['config']['platform']['php'] ?? null;
3340
if ($platformPhp !== null) {
3441
self::$cachedPhpVersions[$composerJson] = PhpVersionFactory::createIntVersion($platformPhp);
3542
return self::$cachedPhpVersions[$composerJson];
3643
}
3744

38-
$requirePhpVersion = $projectComposerJson['require']['php'] ?? null;
39-
if ($requirePhpVersion === null) {
40-
return self::$cachedPhpVersions[$composerJson] = null;
41-
}
42-
43-
self::$cachedPhpVersions[$composerJson] = self::createIntVersionFromComposerVersion($requirePhpVersion);
44-
45-
return self::$cachedPhpVersions[$composerJson];
45+
return null;
4646
}
4747

4848
private static function createIntVersionFromComposerVersion(string $projectPhpVersion): int

src/Util/PhpVersionFactory.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@ public static function createIntVersion(string $version): int
1616
$explodeVersion = explode('.', $version);
1717
$countExplodedVersion = count($explodeVersion);
1818

19-
if ($countExplodedVersion === 2) {
19+
if ($countExplodedVersion >= 2) {
2020
return (int) $explodeVersion[0] * 10000 + (int) $explodeVersion[1] * 100;
2121
}
2222

23-
if ($countExplodedVersion >= 3) {
24-
return (int) $explodeVersion[0] * 10000 + (int) $explodeVersion[1] * 100 + (int) $explodeVersion[2];
25-
}
26-
2723
return (int) $version;
2824
}
2925
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"require": {
3-
"php": ">=7.3"
3+
"php": ">=7.4"
44
},
55
"config": {
66
"platform": {
7-
"php": "7.4"
7+
"php": "7.3"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)