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

RotatingLogger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 59.09%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 40
ccs 13
cts 22
cp 0.5909
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A log() 0 6 1
A __construct() 0 4 1
A initRotating() 0 10 1
A logf() 0 6 1
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