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

CallableMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
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 32
loc 32
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 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