Repository navigation
Report ternary operators that always give one of their branches - #6894
Open
SanderMuller wants to merge 3 commits into
Open
SanderMuller wants to merge 3 commits into
SanderMuller wants to merge 3 commits into
Conversation
The rule is behind the unnecessaryTernary toggle, which bleeding edge turns on. It covers the short ?: form too. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The constant condition and float checks now read the constant values, and the object check uses isObject(), so a mutant of them changes the result. New test cases cover a constant condition and a function that can have side effects. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Adds a bleeding edge rule for a ternary that always gives one of its branches, including the short
?:form.It stays quiet when:
===,!==,!,&&,||,instanceofand calls to functions without side effects count as pure. Property fetches do not, because of__getand hooks.$s === false ? 0 : strlen($s). Self-analysis found this one.-0.0 ?: 0.0gives0.0.SimpleXMLElement. The rule usestoBoolean()for this, so?Countable ?: nullis still reported untiltoBoolean()returnsboolfor these interfaces. ReturnboolfromtoBoolean()ofobject,object{}and interfaces thatSimpleXMLElement,GMPorBcMath\Numbercan implement #6892 proposes that.On a 4.5k-file real-world project it reports one true positive, with no measurable CPU cost (113.9 s on, 113.1 s off, medians of 3).
Closes phpstan/phpstan#15608
🤖 Generated with Claude Code