RequestHandlerResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 39
loc 39
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A resolve() 16 16 4

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\Resolver;
4
5
use Psr\Http\Server\RequestHandlerInterface;
6
use N1215\Jugoya\Wrapper\CallableHandler;
7
use Psr\Container\ContainerInterface;
8
9 View Code Duplication
final class RequestHandlerResolver implements RequestHandlerResolverInterface
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
    use ResolverTrait;
12
13
    /**
14
     * @var ContainerInterface
15
     */
16
    protected $container;
17
18
    /**
19
     * @param ContainerInterface $container
20
     */
21 15
    public function __construct(ContainerInterface $container)
22
    {
23 15
        $this->container = $container;
24 15
    }
25
26
    /**
27
     * @param string|callable|RequestHandlerInterface $ref
28
     * @return RequestHandlerInterface
29
     * @throws UnresolvedException
30
     */
31 13
    public function resolve($ref): RequestHandlerInterface
32
    {
33 13
        if ($ref instanceof RequestHandlerInterface) {
34 3
            return $ref;
35
        }
36
37 10
        if (is_callable($ref)) {
38 3
            return new CallableHandler($ref);
39
        }
40
41 7
        if (!is_string($ref)) {
42 1
            throw new \InvalidArgumentException('Argument 1 $ref must be one of an instance of HandlerInterface, a callable or string.');
43
        }
44
45 6
        return $this->resolveByContainer($ref, $this->container, RequestHandlerInterface::class);
46
    }
47
}
48