LoggerFactory::get()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 7
c 2
b 1
f 0
dl 0
loc 13
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
namespace Oliverde8\PhpEtlBundle\Services;
4
5
use Monolog\Handler\StreamHandler;
6
use Monolog\Logger;
7
use Oliverde8\PhpEtlBundle\Entity\EtlExecution;
8
use Psr\Log\LoggerInterface;
9
10
class LoggerFactory implements LoggerFactoryInterface
11
{
12
    private ChainWorkDirManager $chainWorkDirManager;
13
14
    private LoggerInterface $etlLogger;
15
16
    public function __construct(ChainWorkDirManager $chainWorkDirManager, LoggerInterface $etlLogger)
17
    {
18
        $this->chainWorkDirManager = $chainWorkDirManager;
19
        $this->etlLogger = $etlLogger;
20
    }
21
22
    public function get(EtlExecution $execution): LoggerInterface
23
    {
24
        $logger = new Logger('etl');
25
        $logPath = $this->chainWorkDirManager->getLocalTmpWorkDir($execution);
26
        $logger->pushHandler(new StreamHandler("$logPath/execution.log", Logger::INFO));
27
28
        if ($this->etlLogger instanceof Logger) {
29
            foreach ($this->etlLogger->getHandlers() as $handler) {
0 ignored issues
show
Bug introduced by
The method getHandlers() does not exist on Psr\Log\LoggerInterface. It seems like you code against a sub-type of Psr\Log\LoggerInterface such as Monolog\Logger. ( Ignorable by Annotation )

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

29
            foreach ($this->etlLogger->/** @scrutinizer ignore-call */ getHandlers() as $handler) {
Loading history...
30
                $logger->pushHandler($handler);
31
            }
32
        }
33
34
        return $logger;
35
    }
36
37
}
38