Repository navigation
Add round() throw type extension - #6520
Merged
Merged
Conversation
PhpStorm stubs now declare @throws \ValueError on round(), which made every call an explicit throw point. It is thrown only on PHP 8.4+, for an int $mode that is not one of the eight rounding modes (1-8); older versions accept any mode. The decision reads the native type of $mode, so a PHPDoc-only valid constant keeps the ValueError. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PhpStorm stubs now declare
@throws \ValueErroronround(), so every call became an explicit throw point.round()throwsValueError(Argument #3 ($mode) must be a valid rounding mode (RoundingMode::*)) only on PHP 8.4+, and only for an int$modeoutside the eight rounding modes 1–8. PHP 8.0–8.3 accept any int mode silently, and everyRoundingModecase is always valid.The extension returns
VoidType(no throw point) when:PhpVersion::throwsValueErrorForInvalidRoundingMode()),$modeis not passed,$modeis a subtype ofRoundingMode|int<1, 8>.Otherwise it keeps the declared
ValueError, e.g. forround($f, 0, 9), for a nativeint $mode, and for a PHPDoc-only@param 1 $mode. It also keeps it for unpacked or leftover named arguments.Tests are in
CatchWithUnthrownExceptionRuleTest, with separate expectations for PHP 8.4+ and for PHP < 8.4, where every catch is dead. Both fail without the extension; the < 8.4 expectations were verified locally on PHP 7.4.A side note, not changed here:
resources/functionMap_php80delta.phpstill types$modeas1|2|3|4, so on PHP 8.4+ the valid int modes 5–8 are reported byargument.type(RoundingModecases are accepted).🤖 Generated with Claude Code
https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7