Skip to content

Commit a5e4757

Browse files
committed
IfHandler + applySpecifiedTypes
1 parent 3e05142 commit a5e4757

File tree

8 files changed

+552
-22
lines changed

8 files changed

+552
-22
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ parameters:
2121
-
2222
rawMessage: Casting to string something that's already string.
2323
identifier: cast.useless
24-
count: 2
24+
count: 4
2525
path: src/Analyser/Generator/GeneratorScope.php
2626

2727
-

src/Analyser/Generator/ExprAnalysisRequest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ public function __construct(
3333
$this->originLine = $trace[0]['line'] ?? null;
3434
}
3535

36+
public static function createNoopRequest(Expr $expr, GeneratorScope $scope): self
37+
{
38+
return new ExprAnalysisRequest(new Node\Stmt\Expression($expr), $expr, $scope, ExpressionContext::createTopLevel(), new NoopNodeCallback());
39+
}
40+
3641
}

src/Analyser/Generator/ExprHandler/VariableHandler.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use PHPStan\Analyser\Generator\ExprAnalysisResult;
1111
use PHPStan\Analyser\Generator\ExprHandler;
1212
use PHPStan\Analyser\Generator\GeneratorScope;
13-
use PHPStan\Analyser\SpecifiedTypes;
13+
use PHPStan\Analyser\Generator\SpecifiedTypesHelper;
1414
use PHPStan\DependencyInjection\AutowiredService;
1515
use PHPStan\ShouldNotHappenException;
1616
use PHPStan\Type\ErrorType;
@@ -24,6 +24,12 @@
2424
final class VariableHandler implements ExprHandler
2525
{
2626

27+
public function __construct(
28+
private SpecifiedTypesHelper $specifiedTypesHelper,
29+
)
30+
{
31+
}
32+
2733
public function supports(Expr $expr): bool
2834
{
2935
return $expr instanceof Variable;
@@ -51,8 +57,8 @@ public function analyseExpr(
5157
isAlwaysTerminating: false,
5258
throwPoints: [],
5359
impurePoints: [],
54-
specifiedTruthyTypes: new SpecifiedTypes(),
55-
specifiedFalseyTypes: new SpecifiedTypes(),
60+
specifiedTruthyTypes: $this->specifiedTypesHelper->createDefaultSpecifiedTruthyTypes($expr),
61+
specifiedFalseyTypes: $this->specifiedTypesHelper->createDefaultSpecifiedFalseyTypes($expr),
5662
);
5763
}
5864

@@ -65,8 +71,8 @@ public function analyseExpr(
6571
isAlwaysTerminating: false,
6672
throwPoints: [],
6773
impurePoints: [],
68-
specifiedTruthyTypes: new SpecifiedTypes(),
69-
specifiedFalseyTypes: new SpecifiedTypes(),
74+
specifiedTruthyTypes: $this->specifiedTypesHelper->createDefaultSpecifiedTruthyTypes($expr),
75+
specifiedFalseyTypes: $this->specifiedTypesHelper->createDefaultSpecifiedFalseyTypes($expr),
7076
);
7177
}
7278

0 commit comments

Comments
 (0)