Skip to content

Commit 6c7a981

Browse files
committed
Improved compatibility with PHPStan 1.0
1 parent 17d7c7a commit 6c7a981

File tree

5 files changed

+6
-38
lines changed

5 files changed

+6
-38
lines changed

rules.neon

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ parameters:
1212
reportMaybesInPropertyPhpDocTypes: true
1313

1414
rules:
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

4648
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-
6149
-
6250
class: PHPStan\Rules\BooleansInConditions\BooleanRuleHelper
6351

src/Rules/BooleansInConditions/BooleanInBooleanAndRule.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Rules\BooleansInConditions;
44

5-
use PhpParser\Node\Expr\BinaryOp\BooleanAnd;
65
use PHPStan\Node\BooleanAndNode;
76
use 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);

src/Rules/BooleansInConditions/BooleanInBooleanOrRule.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Rules\BooleansInConditions;
44

5-
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
65
use PHPStan\Node\BooleanOrNode;
76
use 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);

tests/Rules/BooleansInConditions/BooleanInBooleanAndRuleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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

tests/Rules/BooleansInConditions/BooleanInBooleanOrRuleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)