Skip to content

Commit d0009af

Browse files
ondrejmirtesclaude
andcommitted
Accept all eight rounding modes of round() on PHP 8.4
PHP 8.4 added four rounding modes, available as RoundingMode cases or as their int values 5-8, and throws ValueError for any other int. The signature still allowed only 1|2|3|4 besides RoundingMode, so round($f, 0, 5) was reported. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7
1 parent 732eacc commit d0009af

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎resources/functionMap_php84delta.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
'http_clear_last_response_headers' => ['void'],
2121
'mb_lcfirst' => ['string', 'string'=>'string', 'encoding='=>'string'],
2222
'mb_ucfirst' => ['string', 'string'=>'string', 'encoding='=>'string'],
23+
'round' => ['float', 'number'=>'float', 'precision='=>'int', 'mode='=>'int<1, 8>|RoundingMode'],
2324
'simplexml_import_dom' => ['SimpleXMLElement|null', 'node'=>'object', 'class_name='=>'string'],
2425
],
2526
'old' => [
27+
'round' => ['float', 'number'=>'float', 'precision='=>'int', 'mode='=>'1|2|3|4'],
2628
'simplexml_import_dom' => ['SimpleXMLElement|null', 'node'=>'DOMNode', 'class_name='=>'string'],
2729
]
2830
];

‎tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,4 +3151,19 @@ public function testLevenshteinArgumentsCount(): void
31513151
$this->analyse([__DIR__ . '/data/levenshtein-arguments-count.php'], []);
31523152
}
31533153

3154+
#[RequiresPhp('>= 8.4.0')]
3155+
public function testRoundModePhp84(): void
3156+
{
3157+
$this->analyse([__DIR__ . '/data/round-mode-php84.php'], [
3158+
[
3159+
'Parameter #3 $mode of function round expects int<1, 8>|RoundingMode, 9 given.',
3160+
11,
3161+
],
3162+
[
3163+
'Parameter #3 $mode of function round expects int<1, 8>|RoundingMode, 0 given.',
3164+
12,
3165+
],
3166+
]);
3167+
}
3168+
31543169
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace RoundModePhp84;
4+
5+
function doFoo(float $f): void
6+
{
7+
$a = round($f, 0, PHP_ROUND_HALF_UP);
8+
$a = round($f, 0, 5);
9+
$a = round($f, 0, 8);
10+
$a = round($f, 0, \RoundingMode::HalfEven);
11+
$a = round($f, 0, 9);
12+
$a = round($f, 0, 0);
13+
}

0 commit comments

Comments
 (0)