Skip to content

Commit fe194c2

Browse files
committed
InternalStatementExitPoint
1 parent 9f377bf commit fe194c2

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Analyser;
4+
5+
use PhpParser\Node\Stmt;
6+
7+
final class InternalStatementExitPoint
8+
{
9+
10+
public function __construct(private Stmt $statement, private MutatingScope $scope)
11+
{
12+
}
13+
14+
public function toPublic(): StatementExitPoint
15+
{
16+
return new StatementExitPoint($this->statement, $this->scope);
17+
}
18+
19+
public function getStatement(): Stmt
20+
{
21+
return $this->statement;
22+
}
23+
24+
public function getScope(): MutatingScope
25+
{
26+
return $this->scope;
27+
}
28+
29+
}

src/Analyser/InternalStatementResult.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ final class InternalStatementResult
1010
{
1111

1212
/**
13-
* @param StatementExitPoint[] $exitPoints
13+
* @param InternalStatementExitPoint[] $exitPoints
1414
* @param InternalThrowPoint[] $throwPoints
1515
* @param ImpurePoint[] $impurePoints
1616
* @param InternalEndStatementResult[] $endStatements
@@ -33,7 +33,7 @@ public function toPublic(): StatementResult
3333
$this->scope,
3434
$this->hasYield,
3535
$this->isAlwaysTerminating,
36-
$this->exitPoints,
36+
array_map(static fn ($exitPoint) => $exitPoint->toPublic(), $this->exitPoints),
3737
array_map(static fn ($throwPoint) => $throwPoint->toPublic(), $this->throwPoints),
3838
$this->impurePoints,
3939
array_map(static fn ($endStatement) => $endStatement->toPublic(), $this->endStatements),
@@ -83,7 +83,7 @@ public function filterOutLoopExitPoints(): self
8383
}
8484

8585
/**
86-
* @return StatementExitPoint[]
86+
* @return InternalStatementExitPoint[]
8787
*/
8888
public function getExitPoints(): array
8989
{
@@ -92,7 +92,7 @@ public function getExitPoints(): array
9292

9393
/**
9494
* @param class-string<Stmt\Continue_>|class-string<Stmt\Break_> $stmtClass
95-
* @return list<StatementExitPoint>
95+
* @return list<InternalStatementExitPoint>
9696
*/
9797
public function getExitPointsByType(string $stmtClass): array
9898
{
@@ -126,7 +126,7 @@ public function getExitPointsByType(string $stmtClass): array
126126
}
127127

128128
/**
129-
* @return list<StatementExitPoint>
129+
* @return list<InternalStatementExitPoint>
130130
*/
131131
public function getExitPointsForOuterLoop(): array
132132
{
@@ -158,7 +158,7 @@ public function getExitPointsForOuterLoop(): array
158158
$newStatement = new Stmt\Break_($newNode);
159159
}
160160

161-
$exitPoints[] = new StatementExitPoint($newStatement, $exitPoint->getScope());
161+
$exitPoints[] = new InternalStatementExitPoint($newStatement, $exitPoint->getScope());
162162
}
163163

164164
return $exitPoints;

src/Analyser/NodeScopeResolver.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ private function processStmtNode(
895895
}
896896

897897
return new InternalStatementResult($scope, $hasYield, true, [
898-
new StatementExitPoint($stmt, $scope),
898+
new InternalStatementExitPoint($stmt, $scope),
899899
], $overridingThrowPoints ?? $throwPoints, $impurePoints);
900900
} elseif ($stmt instanceof Continue_ || $stmt instanceof Break_) {
901901
if ($stmt->num !== null) {
@@ -911,7 +911,7 @@ private function processStmtNode(
911911
}
912912

913913
return new InternalStatementResult($scope, $hasYield, true, [
914-
new StatementExitPoint($stmt, $scope),
914+
new InternalStatementExitPoint($stmt, $scope),
915915
], $overridingThrowPoints ?? $throwPoints, $impurePoints);
916916
} elseif ($stmt instanceof Node\Stmt\Expression) {
917917
if ($stmt->expr instanceof Expr\Throw_) {
@@ -958,7 +958,7 @@ private function processStmtNode(
958958

959959
if ($earlyTerminationExpr !== null) {
960960
return new InternalStatementResult($scope, $hasYield, true, [
961-
new StatementExitPoint($stmt, $scope),
961+
new InternalStatementExitPoint($stmt, $scope),
962962
], $overridingThrowPoints ?? $throwPoints, $impurePoints);
963963
}
964964
return new InternalStatementResult($scope, $hasYield, $isAlwaysTerminating, [], $overridingThrowPoints ?? $throwPoints, $impurePoints);
@@ -1466,7 +1466,7 @@ private function processStmtNode(
14661466
}
14671467

14681468
$isIterableAtLeastOnce = $beforeCondBooleanType->isTrue()->yes();
1469-
$nodeCallback(new BreaklessWhileLoopNode($stmt, $finalScopeResult->getExitPoints()), $bodyScopeMaybeRan);
1469+
$nodeCallback(new BreaklessWhileLoopNode($stmt, $finalScopeResult->toPublic()->getExitPoints()), $bodyScopeMaybeRan);
14701470

14711471
if ($alwaysIterates) {
14721472
$isAlwaysTerminating = count($finalScopeResult->getExitPointsByType(Break_::class)) === 0;
@@ -1543,7 +1543,7 @@ private function processStmtNode(
15431543
$condBooleanType = ($this->treatPhpDocTypesAsCertain ? $bodyScope->getType($stmt->cond) : $bodyScope->getNativeType($stmt->cond))->toBoolean();
15441544
$alwaysIterates = $condBooleanType->isTrue()->yes() && $context->isTopLevel();
15451545

1546-
$nodeCallback(new DoWhileLoopConditionNode($stmt->cond, $bodyScopeResult->getExitPoints()), $bodyScope);
1546+
$nodeCallback(new DoWhileLoopConditionNode($stmt->cond, $bodyScopeResult->toPublic()->getExitPoints()), $bodyScope);
15471547

15481548
if ($alwaysIterates) {
15491549
$alwaysTerminating = count($bodyScopeResult->getExitPointsByType(Break_::class)) === 0;
@@ -1801,7 +1801,7 @@ private function processStmtNode(
18011801
$finallyScope = null;
18021802
}
18031803
foreach ($branchScopeResult->getExitPoints() as $exitPoint) {
1804-
$finallyExitPoints[] = $exitPoint;
1804+
$finallyExitPoints[] = $exitPoint->toPublic();
18051805
if ($exitPoint->getStatement() instanceof Node\Stmt\Expression && $exitPoint->getStatement()->expr instanceof Expr\Throw_) {
18061806
continue;
18071807
}
@@ -1954,7 +1954,7 @@ private function processStmtNode(
19541954
$finallyScope = $finallyScope->mergeWith($catchScopeForFinally);
19551955
}
19561956
foreach ($catchScopeResult->getExitPoints() as $exitPoint) {
1957-
$finallyExitPoints[] = $exitPoint;
1957+
$finallyExitPoints[] = $exitPoint->toPublic();
19581958
if ($exitPoint->getStatement() instanceof Node\Stmt\Expression && $exitPoint->getStatement()->expr instanceof Expr\Throw_) {
19591959
continue;
19601960
}
@@ -1994,7 +1994,7 @@ private function processStmtNode(
19941994
$finalScope = $finallyResult->isAlwaysTerminating() ? $finalScope : $finalScope->processFinallyScope($finallyScope, $originalFinallyScope);
19951995
if (count($finallyResult->getExitPoints()) > 0) {
19961996
$nodeCallback(new FinallyExitPointsNode(
1997-
$finallyResult->getExitPoints(),
1997+
$finallyResult->toPublic()->getExitPoints(),
19981998
$finallyExitPoints,
19991999
), $scope);
20002000
}

src/Analyser/StatementExitPoint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
final class StatementExitPoint
1111
{
1212

13-
public function __construct(private Stmt $statement, private MutatingScope $scope)
13+
public function __construct(private Stmt $statement, private Scope $scope)
1414
{
1515
}
1616

@@ -19,7 +19,7 @@ public function getStatement(): Stmt
1919
return $this->statement;
2020
}
2121

22-
public function getScope(): MutatingScope
22+
public function getScope(): Scope
2323
{
2424
return $this->scope;
2525
}

0 commit comments

Comments
 (0)