InflectorAggregate   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 47
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 11 2
A inflect() 0 19 4
1
<?php
2
3
namespace League\Container\Inflector;
4
5
use League\Container\ImmutableContainerAwareTrait;
6
7
class InflectorAggregate implements InflectorAggregateInterface
8
{
9
    use ImmutableContainerAwareTrait;
10
11
    /**
12
     * @var array
13
     */
14
    protected $inflectors = [];
15
16
    /**
17
     * [email protected]}
18
     */
19 9
    public function add($type, callable $callback = null)
20
    {
21 9
        if (is_null($callback)) {
22 6
            $inflector = new Inflector;
23 6
            $this->inflectors[$type] = $inflector;
24
25 6
            return $inflector;
26
        }
27
28 3
        $this->inflectors[$type] = $callback;
29 3
    }
30
31
    /**
32
     * [email protected]}
33
     */
34 48
    public function inflect($object)
35
    {
36 48
        foreach ($this->inflectors as $type => $inflector) {
37 6
            if (! $object instanceof $type) {
38 3
                continue;
39
            }
40
41 6
            if ($inflector instanceof Inflector) {
42 3
                $inflector->setContainer($this->getContainer());
43 3
                $inflector->inflect($object);
44 3
                continue;
45
            }
46
47
            // must be dealing with a callable as the inflector
48 3
            call_user_func_array($inflector, [$object]);
49 48
        }
50
51 48
        return $object;
52
    }
53
}
54