DecoratorChain   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 16
dl 0
loc 50
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A addDecorator() 0 3 1
A getDecoratedValue() 0 9 3
A getDefaultDecoratorsSet() 0 11 2
1
<?php
2
3
namespace Er1z\FakeMock\Decorator;
4
5
use Er1z\FakeMock\Metadata\FieldMetadata;
6
use Symfony\Component\Validator\Constraint;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraint was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class DecoratorChain implements DecoratorChainInterface
9
{
10
    /**
11
     * @var DecoratorInterface[]
12
     */
13
    protected $decorators;
14
15
    /**
16
     * DecoratorChain constructor.
17
     *
18
     * @param DecoratorInterface[] $decorators
19
     */
20 74
    public function __construct($decorators = [])
21
    {
22 74
        if (!$decorators) {
23 70
            $decorators = self::getDefaultDecoratorsSet();
24
        }
25
26 74
        foreach ($decorators as $d) {
27 74
            $this->addDecorator($d);
28
        }
29 74
    }
30
31 74
    public static function getDefaultDecoratorsSet()
32
    {
33 74
        $result = [];
34
35 74
        if (class_exists(Constraint::class)) {
36 57
            $result[] = new AssertDecorator();
37
        }
38
39 74
        $result[] = new PhpDocDecorator();
40
41 74
        return $result;
42
    }
43
44 42
    public function getDecoratedValue($value, FieldMetadata $field)
45
    {
46 42
        foreach ($this->decorators as $d) {
47 42
            if (!$d->decorate($value, $field)) {
48 32
                break;
49
            }
50
        }
51
52 42
        return $value;
53
    }
54
55 74
    public function addDecorator(DecoratorInterface $d)
56
    {
57 74
        $this->decorators[] = $d;
58 74
    }
59
}
60