diff --git a/composer.json b/composer.json index 268446d8..f99d2626 100644 --- a/composer.json +++ b/composer.json @@ -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" }, diff --git a/src/HeroFunction.php b/src/HeroFunction.php index ee439cd3..eac4c3a5 100644 --- a/src/HeroFunction.php +++ b/src/HeroFunction.php @@ -4,6 +4,7 @@ namespace ErrorHeroModule; +use ArrayLookup\AtLeast; use Seld\JsonLint\JsonParser; use Throwable; @@ -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 $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); }