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:
12
12
reportMaybesInPropertyPhpDocTypes : true
13
13
14
14
rules :
15
+ - PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule
15
16
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule
17
+ - PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule
16
18
- PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule
17
19
- PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule
18
20
- PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule
@@ -44,20 +46,6 @@ rules:
44
46
- PHPStan\Rules\VariableVariables\VariableVariablesRule
45
47
46
48
services :
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
-
61
49
-
62
50
class : PHPStan\Rules\BooleansInConditions\BooleanRuleHelper
63
51
Original file line number Diff line number Diff line change 2
2
3
3
namespace PHPStan \Rules \BooleansInConditions ;
4
4
5
- use PhpParser \Node \Expr \BinaryOp \BooleanAnd ;
6
5
use PHPStan \Node \BooleanAndNode ;
7
6
use PHPStan \Type \VerbosityLevel ;
8
7
@@ -15,13 +14,9 @@ class BooleanInBooleanAndRule implements \PHPStan\Rules\Rule
15
14
/** @var BooleanRuleHelper */
16
15
private $ helper ;
17
16
18
- /** @var bool */
19
- private $ checkLogicalAndConstantCondition ;
20
-
21
- public function __construct (BooleanRuleHelper $ helper , bool $ checkLogicalAndConstantCondition = false )
17
+ public function __construct (BooleanRuleHelper $ helper )
22
18
{
23
19
$ this ->helper = $ helper ;
24
- $ this ->checkLogicalAndConstantCondition = $ checkLogicalAndConstantCondition ;
25
20
}
26
21
27
22
public function getNodeType (): string
@@ -32,10 +27,6 @@ public function getNodeType(): string
32
27
public function processNode (\PhpParser \Node $ node , \PHPStan \Analyser \Scope $ scope ): array
33
28
{
34
29
$ originalNode = $ node ->getOriginalNode ();
35
- if (!$ originalNode instanceof BooleanAnd && !$ this ->checkLogicalAndConstantCondition ) {
36
- return [];
37
- }
38
-
39
30
$ messages = [];
40
31
if (!$ this ->helper ->passesAsBoolean ($ scope , $ originalNode ->left )) {
41
32
$ leftType = $ scope ->getType ($ originalNode ->left );
Original file line number Diff line number Diff line change 2
2
3
3
namespace PHPStan \Rules \BooleansInConditions ;
4
4
5
- use PhpParser \Node \Expr \BinaryOp \BooleanOr ;
6
5
use PHPStan \Node \BooleanOrNode ;
7
6
use PHPStan \Type \VerbosityLevel ;
8
7
@@ -15,13 +14,9 @@ class BooleanInBooleanOrRule implements \PHPStan\Rules\Rule
15
14
/** @var BooleanRuleHelper */
16
15
private $ helper ;
17
16
18
- /** @var bool */
19
- private $ checkLogicalOrConstantCondition ;
20
-
21
- public function __construct (BooleanRuleHelper $ helper , bool $ checkLogicalOrConstantCondition = false )
17
+ public function __construct (BooleanRuleHelper $ helper )
22
18
{
23
19
$ this ->helper = $ helper ;
24
- $ this ->checkLogicalOrConstantCondition = $ checkLogicalOrConstantCondition ;
25
20
}
26
21
27
22
public function getNodeType (): string
@@ -32,10 +27,6 @@ public function getNodeType(): string
32
27
public function processNode (\PhpParser \Node $ node , \PHPStan \Analyser \Scope $ scope ): array
33
28
{
34
29
$ originalNode = $ node ->getOriginalNode ();
35
- if (!$ originalNode instanceof BooleanOr && !$ this ->checkLogicalOrConstantCondition ) {
36
- return [];
37
- }
38
-
39
30
$ messages = [];
40
31
if (!$ this ->helper ->passesAsBoolean ($ scope , $ originalNode ->left )) {
41
32
$ leftType = $ scope ->getType ($ originalNode ->left );
Original file line number Diff line number Diff line change @@ -16,8 +16,7 @@ protected function getRule(): Rule
16
16
return new BooleanInBooleanAndRule (
17
17
new BooleanRuleHelper (
18
18
self ::getContainer ()->getByType (RuleLevelHelper::class)
19
- ),
20
- true
19
+ )
21
20
);
22
21
}
23
22
Original file line number Diff line number Diff line change @@ -16,8 +16,7 @@ protected function getRule(): Rule
16
16
return new BooleanInBooleanOrRule (
17
17
new BooleanRuleHelper (
18
18
self ::getContainer ()->getByType (RuleLevelHelper::class)
19
- ),
20
- true
19
+ )
21
20
);
22
21
}
23
22
You can’t perform that action at this time.
0 commit comments