77use PHPStan \ExtensionInstaller \GeneratedConfig ;
88use PHPStan \File \FileHelper ;
99use PHPStan \Internal \ComposerHelper ;
10+ use PHPStan \Php \ComposerPhpVersionFactory ;
1011use PHPStan \Php \PhpVersion ;
1112use ReflectionClass ;
1213use 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