anonymous//tests/CanMockHandler.php$0   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 15
rs 10
c 0
b 0
f 0
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
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

22
                $this->assertion = $assertion ?? function (/** @scrutinizer ignore-unused */ $request) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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