Passed
Push — master ( da738a...72a485 )
by Woody
40s
created

LazyHandler::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\Middleware;
5
6
use InvalidArgumentException;
7
use Psr\Container\ContainerInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
12
class LazyHandler implements RequestHandlerInterface
13
{
14
    /** @var ContainerInterface */
15
    private $container;
0 ignored issues
show
Coding Style introduced by
Private member variable "container" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
16
17
    /** @var string */
18
    private $handler;
0 ignored issues
show
Coding Style introduced by
Private member variable "handler" must contain a leading underscore
Loading history...
19
20 3
    public function __construct(ContainerInterface $container, string $handler)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
21
    {
22 3
        if (! is_subclass_of($handler, RequestHandlerInterface::class, true)) {
23 1
            throw new InvalidArgumentException(
24 1
                sprintf('%s does not implement %s', $handler, RequestHandlerInterface::class)
25
            );
26
        }
27
28 2
        $this->container = $container;
29 2
        $this->handler = $handler;
30 2
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
31
32
    // RequestHandlerInterface
33 1
    public function handle(ServerRequestInterface $request): ResponseInterface
34
    {
35 1
        return $this->resolve()->handle($request);
36
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
37
38 1
    private function resolve(): RequestHandlerInterface
39
    {
40 1
        return $this->container->get($this->handler);
41
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
42
}
43