ClassDefinition   A
last analyzed

Coupling/Cohesion

Components 1
Dependencies 1

Complexity

Total Complexity 7

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 61
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1
ccs 22
cts 22
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withMethodCall() 0 9 1
A withMethodCalls() 0 8 2
A build() 0 9 2
A invokeMethods() 0 9 2
1
<?php
2
3
namespace League\Container\Definition;
4
5
use ReflectionClass;
6
7
class ClassDefinition extends AbstractDefinition implements ClassDefinitionInterface
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...
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $methods = [];
13
14
    /**
15
     * [email protected]}
16
     */
17 6
    public function withMethodCall($method, array $args = [])
18
    {
19 6
        $this->methods[] = [
20 6
            'method'    => $method,
21
            'arguments' => $args
22 6
        ];
23
24 6
        return $this;
25
    }
26
27
    /**
28
     * [email protected]}
29
     */
30 3
    public function withMethodCalls(array $methods = [])
31
    {
32 3
        foreach ($methods as $method => $args) {
33 3
            $this->withMethodCall($method, $args);
34 3
        }
35
36 3
        return $this;
37
    }
38
39
    /**
40
     * [email protected]}
41
     */
42 15
    public function build(array $args = [])
43
    {
44 15
        $args       = (empty($args)) ? $this->arguments : $args;
45 15
        $resolved   = $this->resolveArguments($args);
46 15
        $reflection = new ReflectionClass($this->concrete);
47 15
        $instance   = $reflection->newInstanceArgs($resolved);
48
49 15
        return $this->invokeMethods($instance);
50
    }
51
52
    /**
53
     * Invoke methods on resolved instance.
54
     *
55
     * @param  object $instance
56
     * @return object
57
     */
58 15
    protected function invokeMethods($instance)
59
    {
60 15
        foreach ($this->methods as $method) {
61 3
            $args = $this->resolveArguments($method['arguments']);
62 3
            call_user_func_array([$instance, $method['method']], $args);
63 15
        }
64
65 15
        return $instance;
66
    }
67
}
68