Skip to content

Commit

Permalink
Merge pull request #59 from dongm2ez/Fix-php8-non-capturing-catches
Browse files Browse the repository at this point in the history
Fix #57
  • Loading branch information
moufmouf authored Nov 8, 2021
2 parents 4bb334f + de3ed66 commit ed65c3c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function processNode(Node $node, Scope $scope): array
*/
private $unusedThrows = [];

public function __construct(string $catchedVariableName)
public function __construct(?string $catchedVariableName)
{
$this->catchedVariableName = $catchedVariableName;
}
Expand All @@ -66,6 +66,10 @@ public function leaveNode(Node $node)
}
}

if (PHP_VERSION_ID >= 80000 && is_null($this->catchedVariableName)) {
$this->exceptionUsedCount--;
}

if ($node instanceof Node\Stmt\Throw_ && $this->exceptionUsedCount === 0) {
$this->unusedThrows[] = $node;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ class MyCatchException extends \Exception
// This is not okay
throw new \Exception('New exception '.$e->getMessage());
}

try {
}catch (\Exception) {
// This is okay
throw new \Exception();
}

0 comments on commit ed65c3c

Please sign in to comment.