StaticInvocationActivator::createInstance()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
c 0
b 0
f 0
rs 9.2
cc 4
eloc 9
nc 6
nop 3
1
<?php
2
namespace DICIT\Activators;
3
4
use DICIT\Activator;
5
use DICIT\Container;
6
use DICIT\UnbuildableServiceException;
7
8
class StaticInvocationActivator implements Activator
9
{
10
11
    public function createInstance(Container $container, $serviceName, array $serviceConfig)
12
    {
13
        list($className, $methodName) = explode('::', $serviceConfig['builder']);
14
15
        $activationArgs = isset($serviceConfig['arguments']) ?
16
            $container->resolveMany($serviceConfig['arguments']) : array();
17
18
        if (! class_exists($className)) {
19
            throw new UnbuildableServiceException(sprintf("Class '%s' not found.", $className));
20
        } elseif (! method_exists($className, $methodName)) {
21
            throw new UnbuildableServiceException(sprintf("Class '%s' has no '%s' method.", $className, $methodName));
22
        }
23
24
        return call_user_func_array(array($className, $methodName), $activationArgs);
25
    }
26
}
27