File tree Expand file tree Collapse file tree 3 files changed +39
-6
lines changed Expand file tree Collapse file tree 3 files changed +39
-6
lines changed Original file line number Diff line number Diff line change 11
11
class PHPStanDiagnoseExtension implements DiagnoseExtension
12
12
{
13
13
14
+ public function __construct (private PhpVersion $ phpVersion )
15
+ {
16
+ }
17
+
14
18
public function print (Output $ errorOutput ): void
15
19
{
16
20
$ phpRuntimeVersion = new PhpVersion (PHP_VERSION_ID );
17
21
$ errorOutput ->writeLineFormatted (sprintf (
18
22
'<info>PHP runtime version:</info> %s ' ,
19
23
$ phpRuntimeVersion ->getVersionString (),
20
24
));
25
+ $ errorOutput ->writeLineFormatted (sprintf (
26
+ '<info>PHP version for analysis:</info> %s (from %s) ' ,
27
+ $ this ->phpVersion ->getVersionString (),
28
+ $ this ->phpVersion ->getSourceLabel (),
29
+ ));
21
30
$ errorOutput ->writeLineFormatted (sprintf (
22
31
'<info>PHPStan version:</info> %s ' ,
23
32
ComposerHelper::getPhpStanVersion (),
Original file line number Diff line number Diff line change 8
8
class PhpVersion
9
9
{
10
10
11
- public function __construct (private int $ versionId )
11
+ public const SOURCE_RUNTIME = 1 ;
12
+ public const SOURCE_CONFIG = 2 ;
13
+ public const SOURCE_COMPOSER_PLATFORM_PHP = 3 ;
14
+ public const SOURCE_UNKNOWN = 4 ;
15
+
16
+ /**
17
+ * @param self::SOURCE_* $source
18
+ */
19
+ public function __construct (private int $ versionId , private int $ source = self ::SOURCE_UNKNOWN )
12
20
{
13
21
}
14
22
23
+ public function getSourceLabel (): string
24
+ {
25
+ switch ($ this ->source ) {
26
+ case self ::SOURCE_RUNTIME :
27
+ return 'runtime ' ;
28
+ case self ::SOURCE_CONFIG :
29
+ return 'config ' ;
30
+ case self ::SOURCE_COMPOSER_PLATFORM_PHP :
31
+ return 'config.platform.php in composer.json ' ;
32
+ }
33
+
34
+ return 'unknown ' ;
35
+ }
36
+
15
37
public function getVersionId (): int
16
38
{
17
39
return $ this ->versionId ;
Original file line number Diff line number Diff line change @@ -20,18 +20,20 @@ public function __construct(
20
20
public function create (): PhpVersion
21
21
{
22
22
$ versionId = $ this ->versionId ;
23
- if ($ versionId === null && $ this ->composerPhpVersion !== null ) {
23
+ if ($ versionId !== null ) {
24
+ $ source = PhpVersion::SOURCE_CONFIG ;
25
+ } elseif ($ this ->composerPhpVersion !== null ) {
24
26
$ parts = explode ('. ' , $ this ->composerPhpVersion );
25
27
$ tmp = (int ) $ parts [0 ] * 10000 + (int ) ($ parts [1 ] ?? 0 ) * 100 + (int ) ($ parts [2 ] ?? 0 );
26
28
$ tmp = max ($ tmp , 70100 );
27
29
$ versionId = min ($ tmp , 80399 );
28
- }
29
-
30
- if ($ versionId === null ) {
30
+ $ source = PhpVersion::SOURCE_COMPOSER_PLATFORM_PHP ;
31
+ } else {
31
32
$ versionId = PHP_VERSION_ID ;
33
+ $ source = PhpVersion::SOURCE_RUNTIME ;
32
34
}
33
35
34
- return new PhpVersion ($ versionId );
36
+ return new PhpVersion ($ versionId, $ source );
35
37
}
36
38
37
39
}
You can’t perform that action at this time.
0 commit comments