Completed
Push — master ( b479ad...ad12fe )
by n
04:07
created

CallableMiddleware::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace N1215\Jugoya\Wrapper;
4
5
use Interop\Http\ServerMiddleware\DelegateInterface;
6
use Interop\Http\ServerMiddleware\MiddlewareInterface;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
10 View Code Duplication
class CallableMiddleware implements MiddlewareInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
13
    /**
14
     * @var callable
15
     */
16
    private $callable;
17
18
    /**
19
     * @param callable $callable
20
     */
21 6
    public function __construct(callable $callable)
22
    {
23 6
        $this->callable = $callable;
24 6
    }
25
26
    /**
27
     * @param ServerRequestInterface $request
28
     * @param DelegateInterface $delegate
29
     * @return ResponseInterface
30
     */
31 5
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
32
    {
33 5
        $response = call_user_func($this->callable, $request, $delegate);
34
35 5
        if (!$response instanceof ResponseInterface) {
36 1
            throw new \LogicException('callable must return an instance of \Psr\Http\Message\ResponseInterface.');
37
        }
38
39 4
        return $response;
40
    }
41
}
42