Skip to content

Commit e62b21c

Browse files
committed
utilize samsonasik/ArrayLookup
1 parent 73c7f85 commit e62b21c

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"laminas/laminas-psr7bridge": "^1.8",
4545
"laminas/laminas-uri": "^2.10",
4646
"psr/container": "^1.1.2 || 2.0",
47+
"samsonasik/array-lookup": "^1.0",
4748
"seld/jsonlint": "^1.9",
4849
"webmozart/assert": "^1.11"
4950
},

src/HeroFunction.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace ErrorHeroModule;
66

7+
use ArrayLookup\AtLeast;
78
use Seld\JsonLint\JsonParser;
89
use Throwable;
910

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

28-
$isExcluded = false;
29-
foreach ($excludeExceptionsConfig as $excludeExceptionConfig) {
30-
if ($exceptionOrErrorClass === $excludeExceptionConfig) {
31-
$isExcluded = true;
32-
break;
30+
$filter = static function (string|array $excludeExceptionConfig) use ($exceptionOrErrorClass, $message): bool {
31+
if ($excludeExceptionConfig === $exceptionOrErrorClass) {
32+
return true;
3333
}
3434

35-
if (
36-
is_array($excludeExceptionConfig)
35+
return is_array($excludeExceptionConfig)
3736
&& $excludeExceptionConfig[0] === $exceptionOrErrorClass
38-
&& $excludeExceptionConfig[1] === $throwable->getMessage()
39-
) {
40-
$isExcluded = true;
41-
break;
42-
}
43-
}
37+
&& $excludeExceptionConfig[1] === $message;
38+
};
4439

45-
return $isExcluded;
40+
return AtLeast::once($excludeExceptionsConfig, $filter);
4641
}

0 commit comments

Comments
 (0)