Skip to content

Commit 5cad6b5

Browse files
authored
Merge pull request #92 from samsonasik/use-more-array-lookup
More usage of ArrayLookup
2 parents c63d1e6 + a057f75 commit 5cad6b5

File tree

4 files changed

+66
-13
lines changed

4 files changed

+66
-13
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/.gitignore export-ignore
44
/.travis.yml export-ignore
55
/phpstan.neon export-ignore
6+
/phpstan-baseline.neon export-ignore
67
/spec/ export-ignore
78
/CONTRIBUTING.md export-ignore
89
/kahlan-config.php export-ignore

phpstan-baseline.neon

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Access to an undefined property ErrorHeroModule\\\\Command\\\\BaseLoggingCommand\\:\\:\\$request\\.$#"
5+
count: 1
6+
path: src/Command/BaseLoggingCommand.php
7+
8+
-
9+
message: "#^Access to private property \\$this\\(ErrorHeroModule\\\\Command\\\\BaseLoggingCommand\\)&ErrorHeroModule\\\\Listener\\\\Mvc\\:\\:\\$mvcEvent\\.$#"
10+
count: 1
11+
path: src/Command/BaseLoggingCommand.php
12+
13+
-
14+
message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int\\)\\: bool\\)\\|null, array\\{\\$this\\(ErrorHeroModule\\\\Command\\\\BaseLoggingCommand\\)\\|\\(\\$this\\(ErrorHeroModule\\\\Command\\\\BaseLoggingCommand\\)&ErrorHeroModule\\\\Listener\\\\Mvc\\), 'phpErrorHandler'\\} given\\.$#"
15+
count: 1
16+
path: src/Command/BaseLoggingCommand.php
17+
18+
-
19+
message: "#^Invalid type object to throw\\.$#"
20+
count: 1
21+
path: src/Handler/Logging.php
22+
23+
-
24+
message: "#^Access to an undefined property ErrorHeroModule\\\\Listener\\\\Mvc\\:\\:\\$request\\.$#"
25+
count: 1
26+
path: src/Listener/Mvc.php
27+
28+
-
29+
message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int\\)\\: bool\\)\\|null, array\\{\\$this\\(ErrorHeroModule\\\\Listener\\\\Mvc\\)\\|\\(\\$this\\(ErrorHeroModule\\\\Listener\\\\Mvc\\)&ErrorHeroModule\\\\Listener\\\\Mvc\\), 'phpErrorHandler'\\} given\\.$#"
30+
count: 1
31+
path: src/Listener/Mvc.php
32+
33+
-
34+
message: "#^Parameter \\#1 \\$mvcEvent of method ErrorHeroModule\\\\Listener\\\\Mvc\\:\\:exceptionError\\(\\) expects Laminas\\\\Mvc\\\\MvcEvent, ErrorException given\\.$#"
35+
count: 2
36+
path: src/Listener/Mvc.php
37+
38+
-
39+
message: "#^Result of method ErrorHeroModule\\\\Listener\\\\Mvc\\:\\:exceptionError\\(\\) \\(void\\) is used\\.$#"
40+
count: 1
41+
path: src/Listener/Mvc.php
42+
43+
-
44+
message: "#^Access to private property \\$this\\(ErrorHeroModule\\\\Middleware\\\\Mezzio\\)&ErrorHeroModule\\\\Listener\\\\Mvc\\:\\:\\$mvcEvent\\.$#"
45+
count: 4
46+
path: src/Middleware/Mezzio.php
47+
48+
-
49+
message: "#^Parameter \\#1 \\$callback of function set_error_handler expects \\(callable\\(int, string, string, int\\)\\: bool\\)\\|null, array\\{\\$this\\(ErrorHeroModule\\\\Middleware\\\\Mezzio\\)\\|\\(\\$this\\(ErrorHeroModule\\\\Middleware\\\\Mezzio\\)&ErrorHeroModule\\\\Listener\\\\Mvc\\), 'phpErrorHandler'\\} given\\.$#"
50+
count: 1
51+
path: src/Middleware/Mezzio.php
52+
53+
-
54+
message: "#^Parameter \\#1 \\$throwable of method ErrorHeroModule\\\\Middleware\\\\Mezzio\\:\\:exceptionError\\(\\) expects Throwable, Laminas\\\\Mvc\\\\MvcEvent given\\.$#"
55+
count: 1
56+
path: src/Middleware/Mezzio.php

phpstan.neon

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
includes:
22
- vendor/phpstan/phpstan-webmozart-assert/extension.neon
3+
- phpstan-baseline.neon
34

45
parameters:
56
excludePaths:
@@ -10,7 +11,3 @@ parameters:
1011
reportUnmatchedIgnoredErrors: false
1112
treatPhpDocTypesAsCertain: false
1213
checkGenericClassInNonGenericObjectType: false
13-
ignoreErrors:
14-
- '#function set_error_handler expects (callable(int, string, string, int, array): bool)*#'
15-
- '#Invalid type object to throw#'
16-
- '#Instanceof between \*NEVER\* and ErrorHeroModule\\Listener\\Mvc will always evaluate to false#'

src/HeroTrait.php

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

55
namespace ErrorHeroModule;
66

7+
use ArrayLookup\AtLeast;
78
use ErrorException;
89
use ErrorHeroModule\Command\BaseLoggingCommand;
910
use ErrorHeroModule\Listener\Mvc;
@@ -123,18 +124,16 @@ public function phpErrorHandler(int $errorType, string $errorMessage, string $er
123124
return;
124125
}
125126

126-
foreach ($this->errorHeroModuleConfig['display-settings']['exclude-php-errors'] as $excludePhpError) {
127-
if ($errorType === $excludePhpError) {
128-
return;
129-
}
130-
131-
if (
127+
$filter = static fn (mixed $excludePhpError): bool =>
128+
$errorType === $excludePhpError ||
129+
(
132130
is_array($excludePhpError)
133131
&& $excludePhpError[0] === $errorType
134132
&& $excludePhpError[1] === $errorMessage
135-
) {
136-
return;
137-
}
133+
);
134+
135+
if (AtLeast::once($this->errorHeroModuleConfig['display-settings']['exclude-php-errors'], $filter)) {
136+
return;
138137
}
139138

140139
throw new ErrorException($errorMessage, 0, $errorType, $errorFile, $errorLine);

0 commit comments

Comments
 (0)