Formatter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 23 5
1
<?php
2
3
namespace Dafiti\Silex\Log\Factory;
4
5
class Formatter extends AbstractFactory
6
{
7
    public function __invoke(array $args)
8
    {
9
        $this->args = $args;
10
11
        if (!isset($this->args['class']) || empty($this->args['class'])) {
12
            throw new \OutOfBoundsException('You should define key class to create a log formatter');
13
        }
14
15
        $class = new \ReflectionClass($args['class']);
16
        $params = [];
17
18
        if ($constructor = $class->getConstructor()) {
19
            $params = $this->getParams($constructor);
20
        }
21
22
        $object = $class->newInstanceArgs($params);
23
24
        if (!$object instanceof \Monolog\Formatter\FormatterInterface) {
25
            throw new \InvalidArgumentException('Class must be instance of "\Monolog\Formatter\FormatterInterface"');
26
        }
27
28
        return $object;
29
    }
30
}
31