Skip to content

Add numeric check on unary plus and unary minus #273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from

Conversation

VincentLanglet
Copy link
Contributor

@VincentLanglet VincentLanglet commented May 25, 2025

The operation $a + $b and $a - $b were checked but it was mising for the unary usage of these operators +$a or -$a.

Then, I plan to add such check for bitwise operators:

  • & (AND)
  • | (OR)
  • << (Left shift)
  • >> (Right shift)
  • ^ (XOR)

I assume it should be behind a new config option numericOperandsInBitwiseOperators @ondrejmirtes ?

@VincentLanglet VincentLanglet force-pushed the unaryCheck branch 2 times, most recently from c0d321f to dc350fa Compare May 25, 2025 21:37
@@ -6,29 +6,29 @@

[PHPStan](https://phpstan.org/) focuses on finding bugs in your code. But in PHP there's a lot of leeway in how stuff can be written. This repository contains additional rules that revolve around strictly and strongly typed code with no loose casting for those who want additional safety in extremely defensive programming:

| Configuration Parameters | Rule Description |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README diff is unreadable, please make it minimal.

@@ -106,6 +106,10 @@ conditionalTags:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandInArithmeticUnaryMinusRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for bleeding edge. Please check 1.x to see how it was done (it's an array).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants