1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Northwoods\Router; |
||
5 | |||
6 | use Psr\Http\Message\ResponseInterface; |
||
7 | use Psr\Http\Message\ServerRequestInterface; |
||
8 | use Psr\Http\Server\RequestHandlerInterface; |
||
9 | use Nyholm\Psr7\Response; |
||
10 | |||
11 | trait CanMockHandler |
||
12 | { |
||
13 | private function mockHandler(callable $assertion = null): RequestHandlerInterface |
||
14 | { |
||
15 | return new class($assertion) implements RequestHandlerInterface |
||
16 | { |
||
17 | /** @var callable */ |
||
18 | private $assertion; |
||
19 | |||
20 | public function __construct(?callable $assertion) |
||
21 | { |
||
22 | $this->assertion = $assertion ?? function ($request) { |
||
0 ignored issues
–
show
|
|||
23 | return true; |
||
24 | }; |
||
25 | } |
||
26 | |||
27 | public function handle(ServerRequestInterface $request): ResponseInterface |
||
28 | { |
||
29 | return new Response(($this->assertion)($request) ? 200 : 400); |
||
30 | } |
||
31 | }; |
||
32 | } |
||
33 | } |
||
34 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.