Issues (4)

src/Guard.php (1 issue)

1
<?php
2
3
namespace Jasny\Controller;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
8
#[\Attribute]
9
abstract class Guard
10
{
11
    use Traits\Base,
12
        Traits\Header,
13
        Traits\Output,
14
        Traits\CheckRequest,
15
        Traits\CheckResponse;
16
17
    /**
18
     * @return void|null|ResponseInterface|$this
19
     */
20
    abstract public function process();
21
22
    /**
23
     * Invoke guard.
24
     *
25
     * @param ServerRequestInterface $request
26
     * @param ResponseInterface $response
27
     * @return ResponseInterface|null
28
     */
29
    public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ?ResponseInterface
30
    {
31
        $this->request = $request;
32
        $this->response = $response;
33
34
        $args = $this->getFunctionArgs(new \ReflectionMethod($this, 'process'));
35
36
        /** @noinspection PhpMethodParametersCountMismatchInspection */
37
        $result = $this->process(...$args);
38
39
        return $result === $this ? $this->getResponse() : $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result === $this...getResponse() : $result could return the type Jasny\Controller\Guard which is incompatible with the type-hinted return Psr\Http\Message\ResponseInterface|null. Consider adding an additional type-check to rule them out.
Loading history...
40
    }
41
}
42