Passed
Pull Request — master (#30)
by De Cramer
08:52
created

PerExecutionExecutionContext::finalise()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 8
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 16
rs 8.8333
1
<?php
2
declare(strict_types=1);
3
4
namespace Oliverde8\Component\PhpEtl\Model;
5
6
use Oliverde8\Component\PhpEtl\Model\File\FileSystemInterface;
7
use Oliverde8\Component\PhpEtl\Model\File\LocalFileSystem;
8
use Psr\Log\LoggerInterface;
9
10
class PerExecutionExecutionContext extends 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 (class_exists("Monolog\Logger") && $this->logger instanceof \Monolog\Logger) {
0 ignored issues
show
Bug introduced by
The type Monolog\Logger 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...
24
            foreach ($this->logger->getHandlers() as $handler) {
0 ignored issues
show
Bug introduced by
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...
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 Psr\Log\Test\TestLogger. ( 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
}