Inflector   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 95
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A invokeMethod() 0 6 1
A invokeMethods() 0 8 2
A setProperty() 0 6 1
A setProperties() 0 8 2
A inflect() 0 15 3
1
<?php
2
3
namespace League\Container\Inflector;
4
5
use League\Container\ImmutableContainerAwareTrait;
6
use League\Container\Argument\ArgumentResolverInterface;
7
use League\Container\Argument\ArgumentResolverTrait;
8
9
class Inflector implements ArgumentResolverInterface
0 ignored issues
show
Bug introduced by Phil Bennett
There is one abstract method getContainer in this class; you could implement it, or declare this class as abstract.
Loading history...
10
{
11
    use ArgumentResolverTrait;
12
    use ImmutableContainerAwareTrait;
13
14
    /**
15
     * @var array
16
     */
17
    protected $methods = [];
18
19
    /**
20
     * @var array
21
     */
22
    protected $properties = [];
23
24
    /**
25
     * Defines a method to be invoked on the subject object.
26
     *
27
     * @param  string $name
28
     * @param  array  $args
29
     * @return $this
30
     */
31 6
    public function invokeMethod($name, array $args)
32
    {
33 6
        $this->methods[$name] = $args;
34
35 6
        return $this;
36
    }
37
38
    /**
39
     * Defines multiple methods to be invoked on the subject object.
40
     *
41
     * @param  array $methods
42
     * @return $this
43
     */
44 3
    public function invokeMethods(array $methods)
45
    {
46 3
        foreach ($methods as $name => $args) {
47 3
            $this->invokeMethod($name, $args);
48 3
        }
49
50 3
        return $this;
51
    }
52
53
    /**
54
     * Defines a property to be set on the subject object.
55
     *
56
     * @param  string $property
57
     * @param  mixed  $value
58
     * @return $this
59
     */
60 9
    public function setProperty($property, $value)
61
    {
62 9
        $this->properties[$property] = $value;
63
64 9
        return $this;
65
    }
66
67
    /**
68
     * Defines multiple properties to be set on the subject object.
69
     *
70
     * @param  array $properties
71
     * @return $this
72
     */
73 3
    public function setProperties(array $properties)
74
    {
75 3
        foreach ($properties as $property => $value) {
76 3
            $this->setProperty($property, $value);
77 3
        }
78
79 3
        return $this;
80
    }
81
82
    /**
83
     * Apply inflections to an object.
84
     *
85
     * @param  object $object
86
     * @return void
87
     */
88 9
    public function inflect($object)
89
    {
90 9
        $properties = $this->resolveArguments(array_values($this->properties));
91 9
        $properties = array_combine(array_keys($this->properties), $properties);
92
93 9
        foreach ($properties as $property => $value) {
94 6
            $object->{$property} = $value;
95 9
        }
96
97 9
        foreach ($this->methods as $method => $args) {
98 3
            $args = $this->resolveArguments($args);
99
100 3
            call_user_func_array([$object, $method], $args);
101 9
        }
102 9
    }
103
}
104