Skip to content

Commit c63d1e6

Browse files
authored
Merge pull request #91 from samsonasik/utilize-array-lookup
utilize samsonasik/ArrayLookup
2 parents 73c7f85 + 8634bd6 commit c63d1e6

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
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: 13 additions & 15 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,20 @@ function detectMessageContentType(string $message): string
2425
function isExcludedException(array $excludeExceptionsConfig, Throwable $throwable): bool
2526
{
2627
$exceptionOrErrorClass = $throwable::class;
27-
28-
$isExcluded = false;
29-
foreach ($excludeExceptionsConfig as $excludeExceptionConfig) {
30-
if ($exceptionOrErrorClass === $excludeExceptionConfig) {
31-
$isExcluded = true;
32-
break;
28+
$message = $throwable->getMessage();
29+
30+
/**
31+
* @param string|array<int, string> $excludeExceptionConfig
32+
*/
33+
$filter = static function (mixed $excludeExceptionConfig) use ($exceptionOrErrorClass, $message): bool {
34+
if ($excludeExceptionConfig === $exceptionOrErrorClass) {
35+
return true;
3336
}
3437

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

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

0 commit comments

Comments
 (0)