Failed Conditions
Push — master ( 5e6761...398dce )
by Adrien
04:14 queued 01:57
created

LoggerFactory::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 15
cc 2
rs 10
ccs 0
cts 11
cp 0
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Log;
6
7
use Ecodev\Felix\Model\Log;
1 ignored issue
show
Bug introduced by
The type Ecodev\Felix\Model\Log was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Interop\Container\ContainerInterface;
9
use Laminas\Log\Logger;
10
use Laminas\Log\Writer\Stream;
11
use Laminas\ServiceManager\Factory\FactoryInterface;
12
13
class LoggerFactory implements FactoryInterface
14
{
15
    /**
16
     * @var null|Logger
17
     */
18
    private $logger;
19
20
    /**
21
     * @param ContainerInterface $container
22
     * @param string $requestedName
23
     * @param null|array $options
24
     *
25
     * @return Logger
26
     */
27
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
28
    {
29
        if (!$this->logger) {
30
            // Log to file
31
            $this->logger = new Logger();
32
            $fileWriter = new Stream('logs/all.log');
33
            $this->logger->addWriter($fileWriter);
34
35
            // Log to DB
36
            $dbWriter = $container->get(DbWriter::class);
37
            $dbWriter->addFilter(Logger::INFO);
38
            $this->logger->addWriter($dbWriter);
39
        }
40
41
        return $this->logger;
42
    }
43
}
44