From 56d96ecb886f087a95e006400f4e1722e09d34ec Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:31:27 +0100 Subject: [PATCH] Fix wrong PHP_INT_MAX/MIN and PHP_DEBUG PHP 8.4 type * Fix https://github.com/vimeo/psalm/issues/11189 * Fix PHP_DEBUG constant for PHP 8.4 part of https://github.com/vimeo/psalm/issues/11107 --- .../Expression/Fetch/ConstFetchAnalyzer.php | 16 +++++- tests/ConstantTest.php | 55 +++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) 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', + ],*/ ]; } }