RequestHandlerResolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 4
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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