Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the in_array method with is_a when looking up ignored exceptions. #69

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions src/Event/Listener/ConsoleExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Event\ConsoleErrorEvent;

final class ConsoleExceptionListener
final readonly class ConsoleExceptionListener
{
/**
*
*/
public function __construct(
private readonly LoggerInterface $appLogger,
private readonly array $ignoredExceptions = [],
Expand All @@ -24,8 +27,10 @@ public function __construct(
public function __invoke(ConsoleErrorEvent $event): void
{
$exception = $event->getError();
if (in_array($exception::class, $this->ignoredExceptions, true)) {
return;
foreach ($this->ignoredExceptions as $ignoredException) {
if (is_a($exception::class, $ignoredException, true)) {
return;
}
}

$context = [];
Expand Down
9 changes: 6 additions & 3 deletions src/Event/Listener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
use Throwable;
use Traversable;

final class ExceptionListener
final readonly class ExceptionListener
{
/**
* @param Traversable<class-string<ExceptionHandlerInterface>, ExceptionHandlerInterface> $exceptionHandlers
* @param list<class-string> $ignoredExceptions
*/
public function __construct(
private readonly Traversable $exceptionHandlers,
Expand All @@ -43,8 +44,10 @@ public function __invoke(ExceptionEvent $event): void
$event->allowCustomResponseCode();
}

if (in_array($exception::class, $this->ignoredExceptions, true)) {
return;
foreach ($this->ignoredExceptions as $ignoredException) {
if (is_a($exception::class, $ignoredException, true)) {
return;
}
}

$context = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/AnzuTap/AnzuTapTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ public function transformerDataProvider(): array
'content' => [
['type' => 'text', 'marks' => [
['type' => 'link', 'attrs' => [
'href' => '#pp-1',
'variant' => 'anchor',
'href' => 'pp-1',
'nofollow' => false,
'external' => false,
]],
Expand Down