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 1111class PHPStanDiagnoseExtension implements DiagnoseExtension
1212{
1313
14+ public function __construct (private PhpVersion $ phpVersion )
15+ {
16+ }
17+
1418public function print (Output $ errorOutput ): void
1519{
1620$ phpRuntimeVersion = new PhpVersion (PHP_VERSION_ID );
1721$ errorOutput ->writeLineFormatted (sprintf (
1822'<info>PHP runtime version:</info> %s ' ,
1923$ phpRuntimeVersion ->getVersionString (),
2024));
25+ $ errorOutput ->writeLineFormatted (sprintf (
26+ '<info>PHP version for analysis:</info> %s (from %s) ' ,
27+ $ this ->phpVersion ->getVersionString (),
28+ $ this ->phpVersion ->getSourceLabel (),
29+ ));
2130$ errorOutput ->writeLineFormatted (sprintf (
2231'<info>PHPStan version:</info> %s ' ,
2332ComposerHelper::getPhpStanVersion (),
Original file line number Diff line number Diff line change 88class PhpVersion
99{
1010
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 )
1220{
1321}
1422
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+
1537public function getVersionId (): int
1638{
1739return $ this ->versionId ;
Original file line number Diff line number Diff line change @@ -20,18 +20,20 @@ public function __construct(
2020public function create (): PhpVersion
2121{
2222$ versionId = $ this ->versionId ;
23- if ($ versionId === null && $ this ->composerPhpVersion !== null ) {
23+ if ($ versionId !== null ) {
24+ $ source = PhpVersion::SOURCE_CONFIG ;
25+ } elseif ($ this ->composerPhpVersion !== null ) {
2426$ parts = explode ('. ' , $ this ->composerPhpVersion );
2527$ tmp = (int ) $ parts [0 ] * 10000 + (int ) ($ parts [1 ] ?? 0 ) * 100 + (int ) ($ parts [2 ] ?? 0 );
2628$ tmp = max ($ tmp , 70100 );
2729$ versionId = min ($ tmp , 80399 );
28- }
29-
30- if ($ versionId === null ) {
30+ $ source = PhpVersion::SOURCE_COMPOSER_PLATFORM_PHP ;
31+ } else {
3132$ versionId = PHP_VERSION_ID ;
33+ $ source = PhpVersion::SOURCE_RUNTIME ;
3234}
3335
34- return new PhpVersion ($ versionId );
36+ return new PhpVersion ($ versionId, $ source );
3537}
3638
3739}
You can’t perform that action at this time.
0 commit comments