AbstractFactory   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
__invoke() 0 1 ?
A getParams() 0 11 2
B getParam() 0 19 7
1
<?php
2
3
namespace Dafiti\Silex\Log\Factory;
4
5
abstract class AbstractFactory
6
{
7
    protected $args = [];
8
9
    abstract public function __invoke(array $args);
10
11
    protected function getParams(\ReflectionMethod $method)
12
    {
13
        $params = [];
14
15
        foreach ($method->getParameters() as $param) {
16
            $name = $param->getName();
17
            $params[$name] = $this->getParam($param);
18
        }
19
20
        return $params;
21
    }
22
23
    protected function getParam(\ReflectionParameter $param)
24
    {
25
        $name = $param->getName();
26
27
        if (!isset($this->args['params'][$name]) && !$param->isOptional()) {
28
            $message = sprintf('You must define param "%s" for "%s"', $name, $this->args['class']);
29
30
            throw new \OutOfBoundsException($message);
31
        }
32
33
        if (!isset($this->args['params'][$name]) && $param->isOptional()) {
34
            return $param->getDefaultValue();
35
        }
36
37
        $value = $this->args['params'][$name];
38
        $param = is_string($value) && defined($value) ? constant($value) : $value;
39
40
        return $param;
41
    }
42
}
43