diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php index db382c4f914..eee4f7f6b94 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php @@ -25,6 +25,9 @@ use function implode; use function strtolower; +use const PHP_INT_MAX; +use const PHP_INT_MIN; + /** * @internal */ @@ -164,13 +167,22 @@ public static function getGlobalConstType( case 'PHP_MAJOR_VERSION': case 'PHP_MINOR_VERSION': case 'PHP_RELEASE_VERSION': - case 'PHP_DEBUG': case 'PHP_FLOAT_DIG': + return Type::getInt(); + case 'PHP_INT_MIN': + return Type::getInt(false, PHP_INT_MIN); + + case 'PHP_DEBUG': case 'PHP_ZTS': - return Type::getInt(); + if ($codebase->analysis_php_version_id >= 8_04_00) { + return Type::getBool(); + } + return Type::getIntRange(0, 1); case 'PHP_INT_MAX': + return Type::getInt(false, PHP_INT_MAX); + case 'PHP_INT_SIZE': case 'PHP_MAXPATHLEN': case 'PHP_VERSION_ID': diff --git a/tests/ConstantTest.php b/tests/ConstantTest.php index 68b10f2b641..ee25de0f7aa 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -2157,6 +2157,19 @@ interface BarInterface extends MainInterface {} class FooBar implements FooInterface, BarInterface {} PHP, ], + 'phpDebugValid' => [ + 'code' => ' [ + 'code' => ' [], + 'ignored_issues' => [], + 'php_version' => '8.4', + ],*/ ]; } @@ -2724,6 +2737,48 @@ class C { 'error_levels' => [], 'php_version' => '8.2', ], + 'phpIntMaxValue' => [ + 'code' => ' 'TypeDoesNotContainType', + ], + 'phpIntMinValue' => [ + 'code' => ' -100) {} + ', + 'error_message' => 'TypeDoesNotContainType', + ], + 'phpIntMaxValueRedundant' => [ + 'code' => ' 100) {} + ', + 'error_message' => 'RedundantCondition', + ], + 'phpIntMinValueRedundant' => [ + 'code' => ' 'RedundantCondition', + ], + 'phpDebug' => [ + 'code' => ' 'TypeDoesNotContainType', + ], + /*'phpDebug84' => [ + 'code' => ' 'TypeDoesNotContainType', + 'error_levels' => [], + 'php_version' => '8.4', + ],*/ ]; } }