Skip to content

Commit

Permalink
make immutable, add namespace in test
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 21, 2024
1 parent 211a0fb commit 66596b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 29 deletions.
28 changes: 16 additions & 12 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,19 @@ public function processNodes(
continue;
}

$unreachableStatementNode = null;
foreach ($nextStmts as $nextStmt) {
if ($unreachableStatementNode instanceof UnreachableStatementNode) {
$unreachableStatementNode->addNextStatement($nextStmt);
$unreachableStatement = null;
$nextStatements = [];

foreach ($nextStmts as $key => $nextStmt) {
if ($key === 0) {
$unreachableStatement = $nextStmt;
continue;
}

$unreachableStatementNode = new UnreachableStatementNode($nextStmt);
$nextStatements[] = $nextStmt;
}

$nodeCallback($unreachableStatementNode, $scope);
$nodeCallback(new UnreachableStatementNode($unreachableStatement, $nextStatements), $scope);

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 329 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.
}
}

Expand Down Expand Up @@ -417,17 +419,19 @@ public function processStmtNodes(
continue;
}

$unreachableStatementNode = null;
foreach ($nextStmts as $nextStmt) {
if ($unreachableStatementNode instanceof UnreachableStatementNode) {
$unreachableStatementNode->addNextStatement($nextStmt);
$unreachableStatement = null;
$nextStatements = [];

foreach ($nextStmts as $key => $nextStmt) {
if ($key === 0) {
$unreachableStatement = $nextStmt;

Check failure on line 427 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 427 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.
continue;
}

$unreachableStatementNode = new UnreachableStatementNode($nextStmt);
$nextStatements[] = $nextStmt;
}

$nodeCallback($unreachableStatementNode, $scope);
$nodeCallback(new UnreachableStatementNode($unreachableStatement, $nextStatements), $scope);

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.1)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.

Check failure on line 434 in src/Analyser/NodeScopeResolver.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Parameter #1 $originalStatement of class PHPStan\Node\UnreachableStatementNode constructor expects PhpParser\Node\Stmt, PhpParser\Node\Stmt|null given.
}

$statementResult = new StatementResult($scope, $hasYield, $alreadyTerminated, $exitPoints, $throwPoints, $impurePoints);
Expand Down
13 changes: 4 additions & 9 deletions src/Node/UnreachableStatementNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
final class UnreachableStatementNode extends Stmt implements VirtualNode
{

/** @var Stmt[] */
private array $nextStatements = [];

public function __construct(private Stmt $originalStatement)
/** @param Stmt[] $nextStatements */
public function __construct(private Stmt $originalStatement, private array $nextStatements = [])
{
parent::__construct($originalStatement->getAttributes());

$this->nextStatements = $nextStatements;
}

public function getOriginalStatement(): Stmt
Expand All @@ -36,11 +36,6 @@ public function getSubNodeNames(): array
return [];
}

public function addNextStatement(Stmt $stmt): void
{
$this->nextStatements[] = $stmt;
}

/**
* @return Stmt[]
*/
Expand Down
2 changes: 2 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/multiple_unreachable.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace MultipleUnreachable;

/**
* @param 'foo' $foo
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,6 @@ public function testRule(): void
'Dead catch - Exception is never thrown in the try block.',
398,
],
[
'Dead catch - Exception is never thrown in the try block.',
407,
],
[
'Dead catch - Exception is never thrown in the try block.',
432,
Expand Down Expand Up @@ -217,10 +213,6 @@ public function testRuleWithoutReportingUncheckedException(): void
'Dead catch - Exception is never thrown in the try block.',
398,
],
[
'Dead catch - Exception is never thrown in the try block.',
407,
],
[
'Dead catch - Exception is never thrown in the try block.',
432,
Expand Down

0 comments on commit 66596b4

Please sign in to comment.