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

LoggerFactory::__invoke()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 8
c 1
b 0
f 1
nc 8
nop 3
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 5
rs 8.8571
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