Passed
Pull Request — master (#444)
by Alejandro
08:41 queued 05:16
created

LoggerFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
c 0
b 0
f 0
dl 0
loc 27
rs 10
ccs 8
cts 8
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Shlinkio\Shlink\Common\Logger;
5
6
use Cascade\Cascade;
7
use Interop\Container\ContainerInterface;
8
use Interop\Container\Exception\ContainerException;
9
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
10
use Zend\ServiceManager\Exception\ServiceNotFoundException;
11
use Zend\ServiceManager\Factory\FactoryInterface;
12
13
use function count;
14
use function explode;
15
16
class LoggerFactory implements FactoryInterface
17
{
18
    /**
19
     * Create an object
20
     *
21
     * @param  ContainerInterface $container
22
     * @param  string $requestedName
23
     * @param  null|array $options
24
     * @return object
25
     * @throws ServiceNotFoundException if unable to resolve the service.
26
     * @throws ServiceNotCreatedException if an exception is raised when
27
     *     creating a service.
28
     * @throws ContainerException if any other error occurs
29
     */
30 3
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
31
    {
32 3
        $config = $container->has('config') ? $container->get('config') : [];
33 3
        Cascade::fileConfig($config['logger'] ?? ['loggers' => []]);
0 ignored issues
show
Bug introduced by
It seems like $config['logger'] ?? array('loggers' => array()) can also be of type array<string,array>; however, parameter $resource of Cascade\Cascade::fileConfig() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        Cascade::fileConfig(/** @scrutinizer ignore-type */ $config['logger'] ?? ['loggers' => []]);
Loading history...
34
35
        // Compose requested logger name
36 3
        $loggerName = $options['logger_name'] ?? 'Logger';
37 3
        $nameParts = explode('_', $requestedName);
38 3
        if (count($nameParts) > 1) {
39 1
            $loggerName = $nameParts[1];
40
        }
41
42 3
        return Cascade::getLogger($loggerName);
43
    }
44
}
45