File tree Expand file tree Collapse file tree 4 files changed +12
-16
lines changed
rules/Php80/Rector/Class_
tests/Php/PhpVersionResolver/ProjectComposerJsonPhpVersionResolver/Fixture Expand file tree Collapse file tree 4 files changed +12
-16
lines changed Original file line number Diff line number Diff line change 2424use Rector \BetterPhpDocParser \PhpDocManipulator \PhpDocTagRemover ;
2525use Rector \Comments \NodeDocBlock \DocBlockUpdater ;
2626use Rector \Contract \Rector \ConfigurableRectorInterface ;
27+ use Rector \Exception \Configuration \InvalidConfigurationException ;
2728use Rector \Naming \Naming \UseImportsResolver ;
2829use Rector \Php80 \NodeAnalyzer \PhpAttributeAnalyzer ;
2930use Rector \Php80 \NodeFactory \AttrGroupsFactory ;
3334use Rector \PhpAttribute \NodeFactory \PhpAttributeGroupFactory ;
3435use Rector \PhpDocParser \PhpDocParser \PhpDocNodeTraverser ;
3536use Rector \Rector \AbstractRector ;
36- use Rector \Exception \Configuration \InvalidConfigurationException ;
3737use Rector \ValueObject \PhpVersionFeature ;
3838use Rector \VersionBonding \Contract \MinPhpVersionInterface ;
3939use Symplify \RuleDocGenerator \ValueObject \CodeSample \ConfiguredCodeSample ;
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 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}
You can’t perform that action at this time.
0 commit comments