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

LazyMiddleware::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\MiddlewareInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
13
class LazyMiddleware implements MiddlewareInterface
14
{
15
    /** @var ContainerInterface */
16
    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...
17
18
    /** @var string */
19
    private $middleware;
0 ignored issues
show
Coding Style introduced by
Private member variable "middleware" must contain a leading underscore
Loading history...
20
21 3
    public function __construct(ContainerInterface $container, string $middleware)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
22
    {
23 3
        if (! is_subclass_of($middleware, MiddlewareInterface::class, true)) {
24 1
            throw new InvalidArgumentException(
25 1
                sprintf('%s does not implement %s', $middleware, MiddlewareInterface::class)
26
            );
27
        }
28
29 2
        $this->container = $container;
30 2
        $this->middleware = $middleware;
31 2
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
32
33
    // MiddlewareInterface
34 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
35
    {
36 1
        return $this->resolve()->process($request, $handler);
37
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
38
39 1
    private function resolve(): MiddlewareInterface
40
    {
41 1
        return $this->container->get($this->middleware);
42
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
43
}
44