TypeMapResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 26
loc 26
wmc 4
lcom 1
cbo 1
ccs 8
cts 8
cp 1
rs 10

2 Methods

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

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 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