MethodInjector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 31
c 0
b 0
f 0
wmc 5
lcom 0
cbo 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B inject() 0 27 5
1
<?php
2
3
namespace DICIT\Injectors;
4
5
use DICIT\Injector;
6
use DICIT\Container;
7
8
class MethodInjector implements Injector
9
{
10
11
    public function inject(Container $container, $service, array $serviceConfig)
12
    {
13
        $callConfig = array();
14
15
        if (array_key_exists('call', $serviceConfig)) {
16
            $callConfig = $serviceConfig['call'];
17
        }
18
19
        foreach($callConfig as $methodName => $parameters) {
20
            if (false !== strpos($methodName, '[')) {
21
                if (preg_match('`^([^\[]*)\[[0-9]*\]$`i', $methodName, $matches)) {
22
                    $methodToCall = $matches[1];
23
                }
24
                else {
25
                    throw new \RuntimeException(sprintf("Invalid method name '%s'", $methodName));
26
                }
27
            }
28
            else {
29
                $methodToCall = $methodName;
30
            }
31
32
            $convertedParameters = $container->resolveMany($parameters);
33
            call_user_func_array(array($service, $methodToCall), $convertedParameters);
34
        }
35
36
        return true;
37
    }
38
}
39