Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions src/Rule/Nette/RethrowExceptionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,7 @@ public function getNodeType(): string

public function processNode(Node $node, Scope $scope): array
{
$hasGeneralCatch = false;
foreach ($node->catches as $catch) {
foreach ($catch->types as $type) {
$typeClass = (string) $type;
if ($typeClass === 'Exception' || $typeClass === Throwable::class) {
$hasGeneralCatch = true;
break 2;
}
}
}
if (!$hasGeneralCatch) {
if (!$this->hasGeneralCatch($node)) {
return [];
}

Expand Down Expand Up @@ -92,6 +82,20 @@ public function processNode(Node $node, Scope $scope): array
return $messages;
}

private function hasGeneralCatch(TryCatch $node): bool
{
foreach ($node->catches as $catch) {
foreach ($catch->types as $type) {
$typeClass = (string) $type;
if ($typeClass === 'Exception' || $typeClass === Throwable::class) {
return true;
}
}
}

return false;
}

/**
* @param Node|Node[]|scalar $node
* @return string[]
Expand Down
Loading