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

LazyHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 3 1
A __construct() 0 10 2
A resolve() 0 3 1
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