14
14
use function class_exists ;
15
15
use function count ;
16
16
use function dirname ;
17
+ use function end ;
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 ;
24
+ use function is_string ;
22
25
use function sprintf ;
23
26
use function str_starts_with ;
24
27
use function strlen ;
@@ -29,11 +32,13 @@ final class PHPStanDiagnoseExtension implements DiagnoseExtension
29
32
{
30
33
31
34
/**
35
+ * @param int|array{min: int, max: int}|null $configPhpVersion
32
36
* @param string[] $composerAutoloaderProjectPaths
33
37
* @param string [] $allConfigFiles
34
38
*/
35
39
public function __construct (
36
40
private PhpVersion $ phpVersion ,
41
+ private int |array |null $ configPhpVersion ,
37
42
private FileHelper $ fileHelper ,
38
43
private array $ composerAutoloaderProjectPaths ,
39
44
private array $ allConfigFiles ,
@@ -57,11 +62,27 @@ public function print(Output $output): void
57
62
));
58
63
}
59
64
60
- $ output ->writeLineFormatted (sprintf (
61
- '<info>PHP version for analysis:</info> %s (from %s) ' ,
62
- $ this ->phpVersion ->getVersionString (),
63
- $ this ->phpVersion ->getSourceLabel (),
64
- ));
65
+ if (
66
+ $ this ->phpVersion ->getSource () === PhpVersion::SOURCE_CONFIG
67
+ && is_array ($ this ->configPhpVersion )
68
+ ) {
69
+ $ minVersion = new PhpVersion ($ this ->configPhpVersion ['min ' ]);
70
+ $ maxVersion = new PhpVersion ($ this ->configPhpVersion ['max ' ]);
71
+
72
+ $ output ->writeLineFormatted (sprintf (
73
+ '<info>PHP version for analysis:</info> %s-%s (from %s) ' ,
74
+ $ minVersion ->getVersionString (),
75
+ $ maxVersion ->getVersionString (),
76
+ $ this ->phpVersion ->getSourceLabel (),
77
+ ));
78
+
79
+ } else {
80
+ $ output ->writeLineFormatted (sprintf (
81
+ '<info>PHP version for analysis:</info> %s (from %s) ' ,
82
+ $ this ->phpVersion ->getVersionString (),
83
+ $ this ->phpVersion ->getSourceLabel (),
84
+ ));
85
+ }
65
86
$ output ->writeLineFormatted ('' );
66
87
67
88
$ output ->writeLineFormatted (sprintf (
0 commit comments