Total Complexity | 7 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class BaseAccessControlMiddleware extends AbstractMiddleware |
||
13 | { |
||
14 | |||
15 | protected function handle(mixed ...$middlewareParams): HttpResponse|Request |
||
16 | { |
||
17 | if($this->match instanceof MatchRoute) { |
||
18 | $reflection = new \ReflectionMethod($this->match->controller, $this->match->method); |
||
19 | $attributes = $reflection->getAttributes(); |
||
20 | |||
21 | foreach ($attributes as $attribute) { |
||
22 | if(is_subclass_of($attribute->getName(), AbstractAccessControlAttribute::class)) { |
||
23 | return |
||
24 | $this->checkPermissions($attribute->getName(), ...($attribute->getArguments()))? |
||
25 | $this->request : |
||
26 | new RedirectResponse( |
||
27 | Application::getAuthConfig()->login_url, |
||
28 | redirect_after: $this->request->url |
||
29 | ); |
||
30 | } |
||
31 | |||
32 | } |
||
33 | return $this->request; |
||
34 | } |
||
|
|||
35 | } |
||
36 | |||
37 | |||
38 | protected function checkPermissions(string $modifier, mixed ...$params):bool{ |
||
44 | } |
||
45 | |||
47 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: