Handler   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 26 5
1
<?php
2
3
namespace Dafiti\Silex\Log\Factory;
4
5
use Dafiti\Silex\Log\Logger;
6
7
class Handler extends AbstractFactory
8
{
9
    public function __invoke(array $args)
10
    {
11
        $this->args = $args;
12
13
        if (!isset($this->args['class']) || empty($this->args['class'])) {
14
            throw new \OutOfBoundsException('You should define key class to create a log handler');
15
        }
16
17
        if (isset($this->args['params']['level'])) {
18
            $this->args['params']['level'] = Logger::translateLevel($this->args['params']['level']);
19
        }
20
21
        $class = new \ReflectionClass($this->args['class']);
22
        $params = $this->getParams($class->getConstructor());
23
24
        $object = $class->newInstanceArgs($params);
25
26
        if (isset($this->args['formatter'])) {
27
            $formatterFactory = new Formatter();
28
            $formatter = $formatterFactory($this->args['formatter']);
29
30
            $object->setFormatter($formatter);
31
        }
32
33
        return $object;
34
    }
35
}
36