Skip to content

Commit

Permalink
Fix wrong PHP_INT_MAX/MIN and PHP_DEBUG PHP 8.4 type
Browse files Browse the repository at this point in the history
* Fix #11189
* Fix PHP_DEBUG constant for PHP 8.4 part of #11107
  • Loading branch information
kkmuffme committed Dec 23, 2024
1 parent 5abbdf3 commit 37820f0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 171 in src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php

View workflow job for this annotation

GitHub Actions / build

InvalidScalarArgument

src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php:171:48: InvalidScalarArgument: Argument 2 of Psalm\Type::getInt expects int|null, but float(-9.2233720368548E+18) provided (see https://psalm.dev/012)

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':
Expand Down
53 changes: 53 additions & 0 deletions tests/ConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2157,6 +2157,31 @@ interface BarInterface extends MainInterface {}
class FooBar implements FooInterface, BarInterface {}
PHP,
],
'phpIntMaxValueValid' => [
'code' => '<?php
$max = PHP_INT_MAX;
if ($max > 100) {}
',
],
'phpIntMinValueValid' => [
'code' => '<?php
$min = PHP_INT_MIN;
if ($min < -100) {}
',
],
'phpDebugValid' => [
'code' => '<?php
if (PHP_DEBUG === 0) {}
',
],
'phpDebugValid84' => [
'code' => '<?php
if (PHP_DEBUG === false) {}
',
'assertions' => [],
'ignored_issues' => [],
'php_version' => '8.4',
],
];
}

Expand Down Expand Up @@ -2724,6 +2749,34 @@ class C {
'error_levels' => [],
'php_version' => '8.2',
],
'phpIntMaxValue' => [
'code' => '<?php
$max = PHP_INT_MAX;
if ($max < 100) {}
',
'error_message' => 'TypeDoesNotContainType',
],
'phpIntMinValue' => [
'code' => '<?php
$min = PHP_INT_MIN;
if ($min > -100) {}
',
'error_message' => 'TypeDoesNotContainType',
],
'phpDebug' => [
'code' => '<?php
if (PHP_DEBUG === false) {}
',
'error_message' => 'TypeDoesNotContainType',
],
'phpDebug84' => [
'code' => '<?php
if (PHP_DEBUG === 0) {}
',
'error_message' => 'TypeDoesNotContainType',
'error_levels' => [],
'php_version' => '8.4',
],
];
}
}

0 comments on commit 37820f0

Please sign in to comment.