Skip to content

Commit

Permalink
Merge pull request #91 from samsonasik/utilize-array-lookup
Browse files Browse the repository at this point in the history
utilize samsonasik/ArrayLookup
  • Loading branch information
samsonasik authored Jan 11, 2023
2 parents 73c7f85 + 8634bd6 commit c63d1e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 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
28 changes: 13 additions & 15 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,20 @@ function detectMessageContentType(string $message): string
function isExcludedException(array $excludeExceptionsConfig, Throwable $throwable): bool
{
$exceptionOrErrorClass = $throwable::class;

$isExcluded = false;
foreach ($excludeExceptionsConfig as $excludeExceptionConfig) {
if ($exceptionOrErrorClass === $excludeExceptionConfig) {
$isExcluded = true;
break;
$message = $throwable->getMessage();

/**
* @param string|array<int, string> $excludeExceptionConfig
*/
$filter = static function (mixed $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 c63d1e6

Please sign in to comment.