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

CallableDelegate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 31
loc 31
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A process() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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