Handler::__invoke()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.439
c 0
b 0
f 0
cc 5
eloc 14
nc 5
nop 1
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