Add min() and max() throw type extension - #6516
Merged
Merged
Conversation
PhpStorm stubs now declare @throws \ValueError on min() and max(), which made every call an explicit throw point. They throw it only when called with a single empty array: multiple arguments are just compared with each other, and PHP 7 returns false instead. The decision reads native types, so a PHPDoc-only non-empty-array 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 \ValueErroronmin()andmax(), so every call became an explicit throw point. That broke@throws voidfunctions and custom rules that look at explicit throw points:min(max(1, $x), 5)inside an open database transaction was reported by a downstream "transaction not resolved before leaving the method" rule.min()/max()throwValueErroronly when called with a single empty array. With two or more arguments the values are just compared, and PHP 7 returnsfalsewith a warning instead of throwing.The extension returns
VoidType(no throw point) when:Otherwise it keeps the declared
ValueError, e.g. formax($maybeEmptyArray),min([]),max($mixed)ormax(...$listOfLists).All decisions read
Scope::getNativeType(), so a PHPDoc-onlynon-empty-listkeeps theValueErrorwhile a native narrowing likeif ($a === []) { return; }removes it.Tests are in
CatchWithUnthrownExceptionRuleTest, with separate expectations for PHP 8.0+ and for PHP < 8.0, where every catch is dead. Both fail without the extension. The PHP 7.4 expectations were verified locally on a downgraded copy.🤖 Generated with Claude Code
https://claude.ai/code/session_01Dhb4ssXuKVWcVBcNFpsdn7