@@ -26,6 +26,8 @@ final class ComposerPhpVersionFactory
2626 public function __construct (
2727 #[AutowiredParameter]
2828 private array $ composerAutoloaderProjectPaths ,
29+ #[AutowiredParameter(ref: '%featureToggles.composerPhp64Bit% ' )]
30+ private bool $ composerPhp64Bit = false ,
2931 )
3032 {
3133 }
@@ -37,14 +39,14 @@ private function initializeVersions(): void
3739 // don't limit minVersion... PHPStan can analyze even PHP5
3840 $ this ->maxVersion = new PhpVersion (PhpVersionFactory::MAX_PHP_VERSION );
3941
40- // fallback to composer.json based php-version constraint
41- $ composerPhpVersion = $ this ->getComposerRequireVersion ();
42- if ($ composerPhpVersion === null ) {
42+ // fallback to composer.json based php-version constraints
43+ $ composerPhpVersions = $ this ->getComposerRequireVersions ();
44+ if (count ( $ composerPhpVersions ) === 0 ) {
4345 return ;
4446 }
4547
4648 $ parser = new ComposerPhpVersionParser ();
47- [$ minVersion , $ maxVersion ] = $ parser ->parse ($ composerPhpVersion , static function (string $ version , int $ versionId , bool $ isMaxVersion ): PhpVersion {
49+ [$ minVersion , $ maxVersion ] = $ parser ->parse ($ composerPhpVersions , static function (string $ version , int $ versionId , bool $ isMaxVersion ): PhpVersion {
4850 if ($ isMaxVersion && $ version === '6.0.0.0-dev ' ) {
4951 $ versionId = min ($ versionId , PhpVersionFactory::MAX_PHP5_VERSION );
5052 } elseif ($ isMaxVersion && $ version === '8.0.0.0-dev ' ) {
@@ -83,22 +85,34 @@ public function getMaxVersion(): ?PhpVersion
8385 return $ this ->maxVersion ;
8486 }
8587
86- private function getComposerRequireVersion (): ?string
88+ /**
89+ * Composer registers php-64bit as a virtual package carrying the very same version as php,
90+ * so a requirement on either one constrains the PHP version, and requiring both means
91+ * both constraints have to hold at once.
92+ *
93+ * @return list<string>
94+ */
95+ private function getComposerRequireVersions (): array
8796 {
88- $ composerPhpVersion = null ;
97+ $ packageNames = $ this ->composerPhp64Bit ? ['php ' , 'php-64bit ' ] : ['php ' ];
98+ $ composerPhpVersions = [];
8999
90100 if (count ($ this ->composerAutoloaderProjectPaths ) > 0 ) {
91101 $ composer = ComposerHelper::getComposerConfig (end ($ this ->composerAutoloaderProjectPaths ));
92102 if ($ composer !== null ) {
93- $ requiredVersion = $ composer ['require ' ]['php ' ] ?? null ;
103+ foreach ($ packageNames as $ packageName ) {
104+ $ requiredVersion = $ composer ['require ' ][$ packageName ] ?? null ;
105+
106+ if (!is_string ($ requiredVersion )) {
107+ continue ;
108+ }
94109
95- if (is_string ($ requiredVersion )) {
96- $ composerPhpVersion = $ requiredVersion ;
110+ $ composerPhpVersions [] = $ requiredVersion ;
97111 }
98112 }
99113 }
100114
101- return $ composerPhpVersion ;
115+ return $ composerPhpVersions ;
102116 }
103117
104118}
0 commit comments