From 37820f0d02e233bc8c5f785bf8c31f2213160f6b 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 | 13 ++++- tests/ConstantTest.php | 53 +++++++++++++++++++ 2 files changed, 64 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..a5304b21688 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php @@ -164,13 +164,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, -9223372036854775808); + + 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, 9223372036854775807); + case 'PHP_INT_SIZE': case 'PHP_MAXPATHLEN': case 'PHP_VERSION_ID': diff --git a/tests/ConstantTest.php b/tests/ConstantTest.php index 68b10f2b641..e415b25a40c 100644 --- a/tests/ConstantTest.php +++ b/tests/ConstantTest.php @@ -2157,6 +2157,31 @@ interface BarInterface extends MainInterface {} class FooBar implements FooInterface, BarInterface {} PHP, ], + 'phpIntMaxValueValid' => [ + 'code' => ' 100) {} + ', + ], + 'phpIntMinValueValid' => [ + 'code' => ' [ + 'code' => ' [ + 'code' => ' [], + 'ignored_issues' => [], + 'php_version' => '8.4', + ], ]; } @@ -2724,6 +2749,34 @@ class C { 'error_levels' => [], 'php_version' => '8.2', ], + 'phpIntMaxValue' => [ + 'code' => ' 'TypeDoesNotContainType', + ], + 'phpIntMinValue' => [ + 'code' => ' -100) {} + ', + 'error_message' => 'TypeDoesNotContainType', + ], + 'phpDebug' => [ + 'code' => ' 'TypeDoesNotContainType', + ], + 'phpDebug84' => [ + 'code' => ' 'TypeDoesNotContainType', + 'error_levels' => [], + 'php_version' => '8.4', + ], ]; } }