Completed
Push — master ( 9ab4b9...065cdd )
by Alejandro
09:44
created

LoggerFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10
wmc 5
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 14 5
1
<?php
2
namespace Shlinkio\Shlink\Common\Factory;
3
4
use Cascade\Cascade;
5
use Interop\Container\ContainerInterface;
6
use Interop\Container\Exception\ContainerException;
7
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
8
use Zend\ServiceManager\Exception\ServiceNotFoundException;
9
use Zend\ServiceManager\Factory\FactoryInterface;
10
11
class LoggerFactory implements FactoryInterface
12
{
13
    /**
14
     * Create an object
15
     *
16
     * @param  ContainerInterface $container
17
     * @param  string $requestedName
18
     * @param  null|array $options
19
     * @return object
20
     * @throws ServiceNotFoundException if unable to resolve the service.
21
     * @throws ServiceNotCreatedException if an exception is raised when
22
     *     creating a service.
23
     * @throws ContainerException if any other error occurs
24
     */
25 3
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
26
    {
27 3
        $config = $container->has('config') ? $container->get('config') : [];
28 3
        Cascade::fileConfig(isset($config['logger']) ? $config['logger'] : ['loggers' => []]);
29
30
        // Compose requested logger name
31 3
        $loggerName = isset($options) & isset($options['logger_name']) ? $options['logger_name'] : 'Logger';
32 3
        $nameParts = explode('_', $requestedName);
33 3
        if (count($nameParts) > 1) {
34 1
            $loggerName = $nameParts[1];
35 1
        }
36
37 3
        return Cascade::getLogger($loggerName);
38
    }
39
}
40