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

CallableDelegate::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace N1215\Jugoya\Wrapper;
4
5
use Interop\Http\ServerMiddleware\DelegateInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
9 View Code Duplication
class CallableDelegate implements DelegateInterface
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...
10
{
11
12
    /**
13
     * @var callable
14
     */
15
    private $callable;
16
17
    /**
18
     * @param callable $callable
19
     */
20 4
    public function __construct(callable $callable)
21
    {
22 4
        $this->callable = $callable;
23 4
    }
24
25
    /**
26
     * @param ServerRequestInterface $request
27
     * @return ResponseInterface
28
     */
29 3
    public function process(ServerRequestInterface $request)
30
    {
31 3
        $response = call_user_func($this->callable, $request);
32
33 3
        if (!$response instanceof ResponseInterface) {
34 1
            throw new \LogicException('callable must return an instance of Psr\Http\Message\ResponseInterface.');
35
        }
36
37 2
        return $response;
38
    }
39
}
40