InflectorAggregate   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 51
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 7 1
A getIterator() 0 8 2
A inflect() 0 15 3
1
<?php declare(strict_types=1);
2
3
namespace League\Container\Inflector;
4
5
use Generator;
6
use League\Container\ContainerAwareTrait;
7
8
class InflectorAggregate implements InflectorAggregateInterface
9
{
10
    use ContainerAwareTrait;
11
12
    /**
13
     * @var \League\Container\Inflector[]
14
     */
15
    protected $inflectors = [];
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 12
    public function add(string $type, callable $callback = null) : Inflector
21
    {
22 12
        $inflector          = new Inflector($type, $callback);
23 12
        $this->inflectors[] = $inflector;
24
25 12
        return $inflector;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 30
    public function getIterator() : Generator
32
    {
33 30
        $count = count($this->inflectors);
34
35 30
        for ($i = 0; $i < $count; $i++) {
36 9
            yield $this->inflectors[$i];
37
        }
38 30
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 27
    public function inflect($object)
44
    {
45 27
        foreach ($this->getIterator() as $inflector) {
46 6
            $type = $inflector->getType();
47
48 6
            if (! $object instanceof $type) {
49 6
                continue;
50
            }
51
52 6
            $inflector->setContainer($this->getContainer());
53 6
            $inflector->inflect($object);
54
        }
55
56 27
        return $object;
57
    }
58
}
59