Passed
Push — master ( f501a2...a64193 )
by Dominik
03:35
created

LazyMiddlewareAdapter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 40
loc 40
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A __invoke() 10 10 1

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
declare(strict_types=1);
4
5
namespace Chubbyphp\SlimPsr15;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
12 View Code Duplication
final class LazyMiddlewareAdapter
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...
13
{
14
    /**
15
     * @var ContainerInterface
16
     */
17
    private $container;
18
19
    /**
20
     * @var string
21
     */
22
    private $serviceId;
23
24
    /**
25
     * @param ContainerInterface $container
26
     * @param string             $serviceId
27
     */
28 1
    public function __construct(ContainerInterface $container, string $serviceId)
29
    {
30 1
        $this->container = $container;
31 1
        $this->serviceId = $serviceId;
32 1
    }
33
34
    /**
35
     * @param ServerRequestInterface $request
36
     * @param ResponseInterface      $response
37
     * @param callable               $next
38
     *
39
     * @return ResponseInterface
40
     */
41 1
    public function __invoke(
42
        ServerRequestInterface $request,
43
        ResponseInterface $response,
44
        callable $next
45
    ): ResponseInterface {
46
        /** @var MiddlewareInterface $middleware */
47 1
        $middleware = $this->container->get($this->serviceId);
48
49 1
        return $middleware->process($request, new MiddlewareRequestHandlerAdapter($response, $next));
50
    }
51
}
52