File tree Expand file tree Collapse file tree 5 files changed +6
-38
lines changed
src/Rules/BooleansInConditions
tests/Rules/BooleansInConditions Expand file tree Collapse file tree 5 files changed +6
-38
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,9 @@ parameters:
1212 reportMaybesInPropertyPhpDocTypes : true
1313
1414rules :
15+ - PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule
1516 - PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule
17+ - PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule
1618 - PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule
1719 - PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule
1820 - PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule
@@ -44,20 +46,6 @@ rules:
4446 - PHPStan\Rules\VariableVariables\VariableVariablesRule
4547
4648services :
47- -
48- class : PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule
49- arguments :
50- checkLogicalAndConstantCondition : %featureToggles.checkLogicalAndConstantCondition%
51- tags :
52- - phpstan.rules.rule
53-
54- -
55- class : PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule
56- arguments :
57- checkLogicalOrConstantCondition : %featureToggles.checkLogicalOrConstantCondition%
58- tags :
59- - phpstan.rules.rule
60-
6149 -
6250 class : PHPStan\Rules\BooleansInConditions\BooleanRuleHelper
6351
Original file line number Diff line number Diff line change 22
33namespace PHPStan \Rules \BooleansInConditions ;
44
5- use PhpParser \Node \Expr \BinaryOp \BooleanAnd ;
65use PHPStan \Node \BooleanAndNode ;
76use PHPStan \Type \VerbosityLevel ;
87
@@ -15,13 +14,9 @@ class BooleanInBooleanAndRule implements \PHPStan\Rules\Rule
1514 /** @var BooleanRuleHelper */
1615 private $ helper ;
1716
18- /** @var bool */
19- private $ checkLogicalAndConstantCondition ;
20-
21- public function __construct (BooleanRuleHelper $ helper , bool $ checkLogicalAndConstantCondition = false )
17+ public function __construct (BooleanRuleHelper $ helper )
2218 {
2319 $ this ->helper = $ helper ;
24- $ this ->checkLogicalAndConstantCondition = $ checkLogicalAndConstantCondition ;
2520 }
2621
2722 public function getNodeType (): string
@@ -32,10 +27,6 @@ public function getNodeType(): string
3227 public function processNode (\PhpParser \Node $ node , \PHPStan \Analyser \Scope $ scope ): array
3328 {
3429 $ originalNode = $ node ->getOriginalNode ();
35- if (!$ originalNode instanceof BooleanAnd && !$ this ->checkLogicalAndConstantCondition ) {
36- return [];
37- }
38-
3930 $ messages = [];
4031 if (!$ this ->helper ->passesAsBoolean ($ scope , $ originalNode ->left )) {
4132 $ leftType = $ scope ->getType ($ originalNode ->left );
Original file line number Diff line number Diff line change 22
33namespace PHPStan \Rules \BooleansInConditions ;
44
5- use PhpParser \Node \Expr \BinaryOp \BooleanOr ;
65use PHPStan \Node \BooleanOrNode ;
76use PHPStan \Type \VerbosityLevel ;
87
@@ -15,13 +14,9 @@ class BooleanInBooleanOrRule implements \PHPStan\Rules\Rule
1514 /** @var BooleanRuleHelper */
1615 private $ helper ;
1716
18- /** @var bool */
19- private $ checkLogicalOrConstantCondition ;
20-
21- public function __construct (BooleanRuleHelper $ helper , bool $ checkLogicalOrConstantCondition = false )
17+ public function __construct (BooleanRuleHelper $ helper )
2218 {
2319 $ this ->helper = $ helper ;
24- $ this ->checkLogicalOrConstantCondition = $ checkLogicalOrConstantCondition ;
2520 }
2621
2722 public function getNodeType (): string
@@ -32,10 +27,6 @@ public function getNodeType(): string
3227 public function processNode (\PhpParser \Node $ node , \PHPStan \Analyser \Scope $ scope ): array
3328 {
3429 $ originalNode = $ node ->getOriginalNode ();
35- if (!$ originalNode instanceof BooleanOr && !$ this ->checkLogicalOrConstantCondition ) {
36- return [];
37- }
38-
3930 $ messages = [];
4031 if (!$ this ->helper ->passesAsBoolean ($ scope , $ originalNode ->left )) {
4132 $ leftType = $ scope ->getType ($ originalNode ->left );
Original file line number Diff line number Diff line change @@ -16,8 +16,7 @@ protected function getRule(): Rule
1616 return new BooleanInBooleanAndRule (
1717 new BooleanRuleHelper (
1818 self ::getContainer ()->getByType (RuleLevelHelper::class)
19- ),
20- true
19+ )
2120 );
2221 }
2322
Original file line number Diff line number Diff line change @@ -16,8 +16,7 @@ protected function getRule(): Rule
1616 return new BooleanInBooleanOrRule (
1717 new BooleanRuleHelper (
1818 self ::getContainer ()->getByType (RuleLevelHelper::class)
19- ),
20- true
19+ )
2120 );
2221 }
2322
You can’t perform that action at this time.
0 commit comments