Skip to content

Commit e4eae3b

Browse files
committed
If condition improvement
1 parent a52fb61 commit e4eae3b

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ parameters:
4242
count: 1
4343
path: src/Analyser/MutatingScope.php
4444

45-
-
46-
message: '#^Doing instanceof PHPStan\\Type\\Constant\\ConstantBooleanType is error\-prone and deprecated\. Use Type\:\:isTrue\(\) or Type\:\:isFalse\(\) instead\.$#'
47-
identifier: phpstanApi.instanceofType
48-
count: 2
49-
path: src/Analyser/NodeScopeResolver.php
50-
5145
-
5246
message: '#^Doing instanceof PHPStan\\Type\\Constant\\ConstantStringType is error\-prone and deprecated\. Use Type\:\:getConstantStrings\(\) instead\.$#'
5347
identifier: phpstanApi.instanceofType

src/Analyser/NodeScopeResolver.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@
171171
use PHPStan\Type\ClosureType;
172172
use PHPStan\Type\Constant\ConstantArrayType;
173173
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
174-
use PHPStan\Type\Constant\ConstantBooleanType;
175174
use PHPStan\Type\Constant\ConstantIntegerType;
176175
use PHPStan\Type\Constant\ConstantStringType;
177176
use PHPStan\Type\ErrorType;
@@ -1091,7 +1090,7 @@ private function processStmtNode(
10911090

10921091
$branchScopeStatementResult = $this->processStmtNodes($stmt, $stmt->stmts, $condResult->getTruthyScope(), $nodeCallback, $context);
10931092

1094-
if (!$conditionType instanceof ConstantBooleanType || $conditionType->getValue()) {
1093+
if (!$conditionType->isTrue()->no()) {
10951094
$exitPoints = $branchScopeStatementResult->getExitPoints();
10961095
$throwPoints = array_merge($throwPoints, $branchScopeStatementResult->getThrowPoints());
10971096
$impurePoints = array_merge($impurePoints, $branchScopeStatementResult->getImpurePoints());
@@ -1123,13 +1122,8 @@ private function processStmtNode(
11231122

11241123
if (
11251124
!$ifAlwaysTrue
1126-
&& (
1127-
!$lastElseIfConditionIsTrue
1128-
&& (
1129-
!$elseIfConditionType instanceof ConstantBooleanType
1130-
|| $elseIfConditionType->getValue()
1131-
)
1132-
)
1125+
&& !$lastElseIfConditionIsTrue
1126+
&& !$elseIfConditionType->isTrue()->no()
11331127
) {
11341128
$exitPoints = array_merge($exitPoints, $branchScopeStatementResult->getExitPoints());
11351129
$throwPoints = array_merge($throwPoints, $branchScopeStatementResult->getThrowPoints());

0 commit comments

Comments
 (0)