Passed
Push — master ( 92b282...84dd72 )
by n
02:28
created

DelegateResolver::resolve()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 16
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 16
loc 16
ccs 8
cts 8
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 8
nc 4
nop 1
crap 4
1
<?php
2
3
namespace N1215\Jugoya\Resolver;
4
5
use Interop\Http\ServerMiddleware\DelegateInterface;
6
use N1215\Jugoya\Wrapper\CallableDelegate;
7
use Psr\Container\ContainerInterface;
8
9 View Code Duplication
class DelegateResolver implements DelegateResolverInterface
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 11
    public function __construct(ContainerInterface $container)
22
    {
23 11
        $this->container = $container;
24 11
    }
25
26
    /**
27
     * @param string|callable|DelegateInterface $ref
28
     * @return DelegateInterface
29
     * @throws UnresolvedException
30
     */
31 10
    public function resolve($ref)
32
    {
33 10
        if ($ref instanceof DelegateInterface) {
34 2
            return $ref;
35
        }
36
37 8
        if (is_callable($ref)) {
38 2
            return new CallableDelegate($ref);
39
        }
40
41 6
        if (!is_string($ref)) {
42 1
            throw new \InvalidArgumentException("Argument 1 \$ref must be one of an instance of DelegateInterface, a callable or string.");
43
        }
44
45 5
        return $this->resolveByContainer($ref, $this->container, DelegateInterface::class);
46
    }
47
}
48