Test Failed
Pull Request — dev (#1952)
by Janko
02:59
created

PirateLogger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 39
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A logf() 0 6 1
A initRotating() 0 7 1
A log() 0 10 2
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 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...
11
use RuntimeException;
12
use Stu\Module\Config\StuConfigInterface;
13
14
final class PirateLogger implements PirateLoggerInterface
15
{
16 2
    private ?Logger $logger = null;
17
18 2
    public function __construct(
19
        private StuConfigInterface $stuConfig,
20 2
        private Parser $parser
21
    ) {}
22
23 2
    #[Override]
24
    public function initRotating(): void
25
    {
26 1
        $this->logger = new Logger('KAZON');
27
        $this->logger->pushHandler(
28
            new RotatingFileHandler(
29 1
                $this->stuConfig->getGameSettings()->getPirateSettings()->getPirateLogfilePath()
30
            ),
31
        );
32
    }
33 1
34
    #[Override]
35
    public function log(string $message): void
36 1
    {
37
        if ($this->logger === null) {
38
            throw new RuntimeException('logger has not been initialized');
39 1
        }
40 1
41 1
        $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 1
        $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