Passed
Push — master ( c9be78...243230 )
by Nico
22:39
created

PirateLogger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 45%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 39
ccs 9
cts 20
cp 0.45
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

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