Passed
Push — dev ( eeaa0f...91a85a )
by Janko
26:10
created

RotatingLogger::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Logging;
6
7
use JBBCode\Parser;
8
use Monolog\Handler\RotatingFileHandler;
9
use Monolog\Logger;
10
use Noodlehaus\ConfigInterface;
11
use Override;
0 ignored issues
show
Bug introduced by
The type Override 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...
12
13
final class RotatingLogger implements RotatingLoggerInterface
14
{
15
    private ?Logger $logger = null;
16
17 4
    public function __construct(
18
        private ConfigInterface $config,
19
        private Parser $parser
20
    ) {
21 4
    }
22
23 4
    #[Override]
24
    public function initRotating(LoggerTypeEnum $type): void
25
    {
26 4
        $this->logger = new Logger($type->value);
27 4
        $this->logger->pushHandler(
28 4
            new RotatingFileHandler(
29 4
                sprintf(
30 4
                    '%s/%2$s/%2$s.log',
31 4
                    $this->config->get('debug.logging.log_dir'),
32 4
                    $type->value
33 4
                )
34 4
            ),
35 4
        );
36
    }
37
38
    #[Override]
39
    public function log(string $message): void
40
    {
41
        $method = LoggerEnum::LEVEL_METHODS[LoggerEnum::LEVEL_INFO];
0 ignored issues
show
Bug introduced by
The type Stu\Module\Logging\LoggerEnum 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...
42
        $this->logger->$method(
43
            $this->parser->parse($message)->getAsText()
44
        );
45
    }
46
47
    #[Override]
48
    public function logf(string $information, ...$args): void
49
    {
50
        $this->log(vsprintf(
51
            $information,
52
            $args
53
        ));
54
    }
55
}
56