LoggerFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure;
6
7
use Devanych\Di\FactoryInterface;
8
use Exception;
9
use Monolog\Logger;
10
use Monolog\Handler\StreamHandler;
11
use Psr\Container\ContainerInterface;
12
use Psr\Log\LoggerInterface;
13
14
final class LoggerFactory implements FactoryInterface
15
{
16
    /**
17
     * @param ContainerInterface $container
18
     * @return LoggerInterface
19
     * @throws Exception
20
     * @psalm-suppress MixedArgument
21
     * @psalm-suppress MixedArrayAccess
22
     * @psalm-suppress MixedAssignment
23
     * @psalm-suppress DeprecatedConstant
24
     */
25 6
    public function create(ContainerInterface $container): LoggerInterface
26
    {
27 6
        $logger = new Logger('App');
28 6
        $config = $container->get('config');
29
30 5
        $logger->pushHandler(new StreamHandler(
31 5
            $config['log_file'],
32 5
            $config['debug'] ? Logger::DEBUG : Logger::WARNING
33 5
        ));
34
35 5
        return $logger;
36
    }
37
}
38