TypeMapResolver::__construct()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace mindplay\unravel\resolvers;
4
5
use mindplay\unravel\Resolver;
6
use mindplay\unravel\TypeReflector;
7
use ReflectionParameter;
8
9
/**
10
 * Resolves type-hints against a map where parameter type => value
11
 */
12 View Code Duplication
class TypeMapResolver implements Resolver
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 array
16
     */
17
    private $map;
18
19
    /**
20
     * @param array $map map where fully-qualified class-name => parameter value
21
     */
22 1
    public function __construct($map)
23
    {
24 1
        $this->map = $map;
25 1
    }
26
27 1
    public function resolve(ReflectionParameter $param, $next)
28
    {
29 1
        $type = TypeReflector::getTypeName($param);
30
31 1
        if ($type !== null && array_key_exists($type, $this->map)) {
32 1
            return $this->map[$type];
33
        }
34
35 1
        return $next($param);
36
    }
37
}
38