7
7
use PHPStan \ExtensionInstaller \GeneratedConfig ;
8
8
use PHPStan \File \FileHelper ;
9
9
use PHPStan \Internal \ComposerHelper ;
10
+ use PHPStan \Php \ComposerPhpVersionFactory ;
10
11
use PHPStan \Php \PhpVersion ;
11
12
use ReflectionClass ;
12
13
use function array_key_exists ;
17
18
use function explode ;
18
19
use function implode ;
19
20
use function in_array ;
21
+ use function is_array ;
20
22
use function is_file ;
21
23
use function is_readable ;
22
24
use function sprintf ;
@@ -29,14 +31,17 @@ final class PHPStanDiagnoseExtension implements DiagnoseExtension
29
31
{
30
32
31
33
/**
34
+ * @param int|array{min: int, max: int}|null $configPhpVersion
32
35
* @param string[] $composerAutoloaderProjectPaths
33
36
* @param string [] $allConfigFiles
34
37
*/
35
38
public function __construct (
36
39
private PhpVersion $ phpVersion ,
40
+ private int |array |null $ configPhpVersion ,
37
41
private FileHelper $ fileHelper ,
38
42
private array $ composerAutoloaderProjectPaths ,
39
43
private array $ allConfigFiles ,
44
+ private ComposerPhpVersionFactory $ composerPhpVersionFactory ,
40
45
)
41
46
{
42
47
}
@@ -48,11 +53,45 @@ public function print(Output $output): void
48
53
'<info>PHP runtime version:</info> %s ' ,
49
54
$ phpRuntimeVersion ->getVersionString (),
50
55
));
51
- $ output ->writeLineFormatted (sprintf (
52
- '<info>PHP version for analysis:</info> %s (from %s) ' ,
53
- $ this ->phpVersion ->getVersionString (),
54
- $ this ->phpVersion ->getSourceLabel (),
55
- ));
56
+
57
+ if (
58
+ $ this ->phpVersion ->getSource () === PhpVersion::SOURCE_CONFIG
59
+ && is_array ($ this ->configPhpVersion )
60
+ ) {
61
+ $ minVersion = new PhpVersion ($ this ->configPhpVersion ['min ' ]);
62
+ $ maxVersion = new PhpVersion ($ this ->configPhpVersion ['max ' ]);
63
+
64
+ $ output ->writeLineFormatted (sprintf (
65
+ '<info>PHP version for analysis:</info> %s-%s (from %s) ' ,
66
+ $ minVersion ->getVersionString (),
67
+ $ maxVersion ->getVersionString (),
68
+ $ this ->phpVersion ->getSourceLabel (),
69
+ ));
70
+
71
+ } else {
72
+ $ minComposerPhpVersion = $ this ->composerPhpVersionFactory ->getMinVersion ();
73
+ $ maxComposerPhpVersion = $ this ->composerPhpVersionFactory ->getMaxVersion ();
74
+ if ($ minComposerPhpVersion !== null && $ maxComposerPhpVersion !== null ) {
75
+ if ($ minComposerPhpVersion ->getVersionId () !== $ maxComposerPhpVersion ->getVersionId ()) {
76
+ $ output ->writeLineFormatted (sprintf (
77
+ '<info>PHP composer.json required version:</info> %s-%s ' ,
78
+ $ minComposerPhpVersion ->getVersionString (),
79
+ $ maxComposerPhpVersion ->getVersionString (),
80
+ ));
81
+ } else {
82
+ $ output ->writeLineFormatted (sprintf (
83
+ '<info>PHP composer.json required version:</info> %s ' ,
84
+ $ minComposerPhpVersion ->getVersionString (),
85
+ ));
86
+ }
87
+ }
88
+
89
+ $ output ->writeLineFormatted (sprintf (
90
+ '<info>PHP version for analysis:</info> %s (from %s) ' ,
91
+ $ this ->phpVersion ->getVersionString (),
92
+ $ this ->phpVersion ->getSourceLabel (),
93
+ ));
94
+ }
56
95
$ output ->writeLineFormatted ('' );
57
96
58
97
$ output ->writeLineFormatted (sprintf (
0 commit comments