Repository navigation
PHPStan: Enable numericOperandsInArithmeticOperators strict rule - #87057
Merged
westonruter merged 4 commits intoNov 19, 2026
Merged
westonruter merged 4 commits into
westonruter merged 4 commits into
Conversation
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the |
noruzzamans
marked this pull request as ready for review
November 19, 2026 02:50
noruzzamans
requested review from
fabiankaegy,
juanmaguitar and
westonruter
as code owners
November 19, 2026 02:50
The rules.neon of phpstan-strict-rules ties twelve rules to strictRules.numericOperandsInArithmeticOperators, but only ten were registered, leaving out OperandInArithmeticUnaryMinusRule and OperandInArithmeticUnaryPlusRule, which rules.neon enables only with bleedingEdge. Since the documented local phpstan.neon sets the parameter to false to avoid running the registered rules twice, it also turned off the rules.neon copies of these two, so with bleedingEdge enabled a unary operand such as -$bool went unchecked. The code complies with both rules, so register them unconditionally alongside the others. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
Member
This gave me a This seems to be better code to reproduce this: function repro( bool $b, array $a ) {
$x = $b + 5;
$z = -$b;
}In |
It was 141 characters on one line, while the comment blocks around it wrap at 120. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
PHPStan merges the identical errors that two copies of a rule report, so including rules.neon without disabling the rules phpstan.neon.dist already registers does not report each error twice. It does run each of those rules twice, which is the reason to disable them. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> Claude-Code-Session-Id: dd6ba841-fda3-4a15-8474-62f4e9285131
westonruter
approved these changes
Nov 19, 2026
Vedant-Gandhi
pushed a commit
to Vedant-Gandhi/gutenberg
that referenced
this pull request
Nov 30, 2026
…dPress#87057) * PHPStan: Enable numericOperandsInArithmeticOperators strict rule * Register the unary minus and plus operand rules too The rules.neon of phpstan-strict-rules ties twelve rules to strictRules.numericOperandsInArithmeticOperators, but only ten were registered, leaving out OperandInArithmeticUnaryMinusRule and OperandInArithmeticUnaryPlusRule, which rules.neon enables only with bleedingEdge. Since the documented local phpstan.neon sets the parameter to false to avoid running the registered rules twice, it also turned off the rules.neon copies of these two, so with bleedingEdge enabled a unary operand such as -$bool went unchecked. The code complies with both rules, so register them unconditionally alongside the others. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> * Shorten the numeric operands comment under rules It was 141 characters on one line, while the comment blocks around it wrap at 120. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> * Correct why the registered strict rules are disabled locally PHPStan merges the identical errors that two copies of a rule report, so including rules.neon without disabling the rules phpstan.neon.dist already registers does not report each error twice. It does run each of those rules twice, which is the reason to disable them. Co-Authored-By: Claude Opus 5.5 (medium effort) <noreply@anthropic.com> --------- Co-authored-by: noruzzamans <noruzzaman@git.wordpress.org> Co-authored-by: westonruter <westonruter@git.wordpress.org>
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.
What?
Follow up to #86460.
Enables the
numericOperandsInArithmeticOperatorsstrict rule fromphpstan-strict-rulesby default inphpstan.neon.dist.Why?
As evaluated and documented in #86460, Gutenberg's codebase already complies with
numericOperandsInArithmeticOperators, reporting zero errors across all analyzed files. Enabling this rule ensures that arithmetic operations (+,-,*,/,%,**,++,--) are performed strictly on numeric types, catching non-numeric operand regressions that level 5 lets through.How?
PHPStan\Rules\Operators\OperatorRuleHelperunderservices:withautowired: false. This avoids conflicting withvendor/phpstan/phpstan-strict-rules/rules.neon, which also registers an autowiredOperatorRuleHelper, ensuring that localphpstan.neonconfigs includingrules.neonload cleanly without failing with "Multiple services of typePHPStan\Rules\Operators\OperatorRuleHelperfound".@operatorRuleHelperexplicitly with thephpstan.rules.ruletag:OperandInArithmeticPostDecrementRuleOperandInArithmeticPostIncrementRuleOperandInArithmeticPreDecrementRuleOperandInArithmeticPreIncrementRuleOperandsInArithmeticAdditionRuleOperandsInArithmeticDivisionRuleOperandsInArithmeticExponentiationRuleOperandsInArithmeticModuloRuleOperandsInArithmeticMultiplicationRuleOperandsInArithmeticSubtractionRuledocs/contributors/code/coding-guidelines.mdto disablenumericOperandsInArithmeticOperators: falseto prevent duplicate error reporting when a localphpstan.neonincludesrules.neon.Testing Instructions
composer phpstan(ornpm run typecheck:php). Verify analysis finishes with zero errors.'invalid' + 5;. Runcomposer phpstanand verifyplus.leftNonNumericis reported.phpstan.neonincludingvendor/phpstan/phpstan-strict-rules/rules.neonand verify PHPStan loads cleanly without multiple service definition errors.