Skip to content

Commit

Permalink
utilize samsonasik/ArrayLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 11, 2023
1 parent 73c7f85 commit e62b21c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"laminas/laminas-psr7bridge": "^1.8",
"laminas/laminas-uri": "^2.10",
"psr/container": "^1.1.2 || 2.0",
"samsonasik/array-lookup": "^1.0",
"seld/jsonlint": "^1.9",
"webmozart/assert": "^1.11"
},
Expand Down
23 changes: 9 additions & 14 deletions src/HeroFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ErrorHeroModule;

use ArrayLookup\AtLeast;
use Seld\JsonLint\JsonParser;
use Throwable;

Expand All @@ -24,23 +25,17 @@ function detectMessageContentType(string $message): string
function isExcludedException(array $excludeExceptionsConfig, Throwable $throwable): bool
{
$exceptionOrErrorClass = $throwable::class;
$message = $throwable->getMessage();

$isExcluded = false;
foreach ($excludeExceptionsConfig as $excludeExceptionConfig) {
if ($exceptionOrErrorClass === $excludeExceptionConfig) {
$isExcluded = true;
break;
$filter = static function (string|array $excludeExceptionConfig) use ($exceptionOrErrorClass, $message): bool {
if ($excludeExceptionConfig === $exceptionOrErrorClass) {
return true;
}

if (
is_array($excludeExceptionConfig)
return is_array($excludeExceptionConfig)
&& $excludeExceptionConfig[0] === $exceptionOrErrorClass
&& $excludeExceptionConfig[1] === $throwable->getMessage()
) {
$isExcluded = true;
break;
}
}
&& $excludeExceptionConfig[1] === $message;
};

return $isExcluded;
return AtLeast::once($excludeExceptionsConfig, $filter);
}

0 comments on commit e62b21c

Please sign in to comment.