Issues (24)

Model/ExecutionContext.php (2 issues)

Labels
Severity
1
<?php
2
3
namespace Oliverde8\PhpEtlBundle\Model;
4
5
use Monolog\Logger;
6
use Oliverde8\Component\PhpEtl\Model\File\FileSystemInterface;
7
use Oliverde8\Component\PhpEtl\Model\File\LocalFileSystem;
8
use Psr\Log\LoggerInterface;
9
10
class ExecutionContext extends \Oliverde8\Component\PhpEtl\Model\ExecutionContext
11
{
12
    protected string $workDir;
13
14
    public function __construct(array $parameters, FileSystemInterface $fileSystem, LoggerInterface $logger, string $logPath)
15
    {
16
        parent::__construct($parameters, $fileSystem);
17
        $this->logger = $logger;
18
        $this->workDir = $logPath;
19
    }
20
21
    protected function finalise(): void
22
    {
23
        if ($this->logger instanceof Logger) {
24
            foreach ($this->logger->getHandlers() as $handler) {
0 ignored issues
show
The method getHandlers() does not exist on null. ( Ignorable by Annotation )

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

24
            foreach ($this->logger->/** @scrutinizer ignore-call */ getHandlers() as $handler) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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

24
            foreach ($this->logger->/** @scrutinizer ignore-call */ getHandlers() as $handler) {
Loading history...
25
                $handler->close();
26
            }
27
        }
28
29
        if ($this->fileSystem instanceof LocalFileSystem && $this->fileSystem->getRootPath() == $this->workDir) {
30
            // Local file system needs no moving of the log file.
31
            return;
32
        }
33
34
        $logPath = $this->workDir . "/execution.log";
35
        if(file_exists($logPath)) {
36
            $this->fileSystem->writeStream("execution.log", fopen($logPath, 'r'));
37
        }
38
    }
39
}
40