Completed
Push — master ( b479ad...ad12fe )
by n
04:07
created

MiddlewareResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace N1215\Jugoya\Resolver;
4
5
use Interop\Http\ServerMiddleware\MiddlewareInterface;
6
use N1215\Jugoya\Wrapper\CallableMiddleware;
7
use Psr\Container\ContainerInterface;
8
9 View Code Duplication
class MiddlewareResolver implements MiddlewareResolverInterface
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
12
    /**
13
     * @var ContainerInterface
14
     */
15
    private $container;
16
17
    /**
18
     * @param ContainerInterface $container
19
     */
20 8
    public function __construct(ContainerInterface $container)
21
    {
22 8
        $this->container = $container;
23 8
    }
24
25
    /**
26
     * @param string|callable|MiddlewareInterface $entry
27
     * @return MiddlewareInterface
28
     */
29 7
    public function resolve($entry)
30
    {
31 7
        if ($entry instanceof MiddlewareInterface) {
32 4
            return $entry;
33
        }
34
35 6
        if (is_callable($entry)) {
36 4
            return new CallableMiddleware($entry);
37
        }
38
39 5
        if (!is_string($entry)) {
40 1
            throw new \InvalidArgumentException('$entry must be one of a MiddlewareInterface, a callable or string');
41
        }
42
43 4
        return $this->container->get($entry);
44
    }
45
}
46