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

LazyRequestHandlerAdapter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 35
loc 35
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() 7 7 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\RequestHandlerInterface;
11
12 View Code Duplication
final class LazyRequestHandlerAdapter
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
     *
37
     * @return ResponseInterface
38
     */
39 1
    public function __invoke(ServerRequestInterface $request): ResponseInterface
40
    {
41
        /** @var RequestHandlerInterface $requestHandler */
42 1
        $requestHandler = $this->container->get($this->serviceId);
43
44 1
        return $requestHandler->handle($request);
45
    }
46
}
47