Skip to content

Commit 66596b4

Browse files
committed
make immutable, add namespace in test
1 parent 211a0fb commit 66596b4

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -314,17 +314,19 @@ public function processNodes(
314314
continue;
315315
}
316316

317-
$unreachableStatementNode = null;
318-
foreach ($nextStmts as $nextStmt) {
319-
if ($unreachableStatementNode instanceof UnreachableStatementNode) {
320-
$unreachableStatementNode->addNextStatement($nextStmt);
317+
$unreachableStatement = null;
318+
$nextStatements = [];
319+
320+
foreach ($nextStmts as $key => $nextStmt) {
321+
if ($key === 0) {
322+
$unreachableStatement = $nextStmt;
321323
continue;
322324
}
323325

324-
$unreachableStatementNode = new UnreachableStatementNode($nextStmt);
326+
$nextStatements[] = $nextStmt;
325327
}
326328

327-
$nodeCallback($unreachableStatementNode, $scope);
329+
$nodeCallback(new UnreachableStatementNode($unreachableStatement, $nextStatements), $scope);
328330
}
329331
}
330332

@@ -417,17 +419,19 @@ public function processStmtNodes(
417419
continue;
418420
}
419421

420-
$unreachableStatementNode = null;
421-
foreach ($nextStmts as $nextStmt) {
422-
if ($unreachableStatementNode instanceof UnreachableStatementNode) {
423-
$unreachableStatementNode->addNextStatement($nextStmt);
422+
$unreachableStatement = null;
423+
$nextStatements = [];
424+
425+
foreach ($nextStmts as $key => $nextStmt) {
426+
if ($key === 0) {
427+
$unreachableStatement = $nextStmt;
424428
continue;
425429
}
426430

427-
$unreachableStatementNode = new UnreachableStatementNode($nextStmt);
431+
$nextStatements[] = $nextStmt;
428432
}
429433

430-
$nodeCallback($unreachableStatementNode, $scope);
434+
$nodeCallback(new UnreachableStatementNode($unreachableStatement, $nextStatements), $scope);
431435
}
432436

433437
$statementResult = new StatementResult($scope, $hasYield, $alreadyTerminated, $exitPoints, $throwPoints, $impurePoints);

src/Node/UnreachableStatementNode.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
final class UnreachableStatementNode extends Stmt implements VirtualNode
1111
{
1212

13-
/** @var Stmt[] */
14-
private array $nextStatements = [];
15-
16-
public function __construct(private Stmt $originalStatement)
13+
/** @param Stmt[] $nextStatements */
14+
public function __construct(private Stmt $originalStatement, private array $nextStatements = [])
1715
{
1816
parent::__construct($originalStatement->getAttributes());
17+
18+
$this->nextStatements = $nextStatements;
1919
}
2020

2121
public function getOriginalStatement(): Stmt
@@ -36,11 +36,6 @@ public function getSubNodeNames(): array
3636
return [];
3737
}
3838

39-
public function addNextStatement(Stmt $stmt): void
40-
{
41-
$this->nextStatements[] = $stmt;
42-
}
43-
4439
/**
4540
* @return Stmt[]
4641
*/

tests/PHPStan/Rules/DeadCode/data/multiple_unreachable.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
namespace MultipleUnreachable;
4+
35
/**
46
* @param 'foo' $foo
57
*/

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ public function testRule(): void
105105
'Dead catch - Exception is never thrown in the try block.',
106106
398,
107107
],
108-
[
109-
'Dead catch - Exception is never thrown in the try block.',
110-
407,
111-
],
112108
[
113109
'Dead catch - Exception is never thrown in the try block.',
114110
432,
@@ -217,10 +213,6 @@ public function testRuleWithoutReportingUncheckedException(): void
217213
'Dead catch - Exception is never thrown in the try block.',
218214
398,
219215
],
220-
[
221-
'Dead catch - Exception is never thrown in the try block.',
222-
407,
223-
],
224216
[
225217
'Dead catch - Exception is never thrown in the try block.',
226218
432,

0 commit comments

Comments
 (0)