Passed
Push — master ( bf860f...1dd8f7 )
by Nico
57:55 queued 29:36
created

PirateLogger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 33
ccs 9
cts 18
cp 0.5
rs 10
c 2
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A initRotating() 0 6 1
A logf() 0 5 1
A __construct() 0 4 1
A log() 0 5 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 Stu\Module\Config\StuConfigInterface;
11
12
final class PirateLogger implements PirateLoggerInterface
13
{
14
    private ?Logger $logger = null;
15
16 1
    public function __construct(
17
        private StuConfigInterface $stuConfig,
18
        private Parser $parser
19
    ) {
20 1
    }
21
22 1
    public function initRotating(): void
23
    {
24 1
        $this->logger = new Logger('KAZON');
25 1
        $this->logger->pushHandler(
26 1
            new RotatingFileHandler(
27 1
                $this->stuConfig->getGameSettings()->getPirateLogfilePath()
28 1
            ),
29 1
        );
30
    }
31
32
    public function log(string $message): void
33
    {
34
        $method = LoggerEnum::LEVEL_METHODS[LoggerEnum::LEVEL_INFO];
35
        $this->logger->$method(
36
            $this->parser->parse($message)->getAsText()
37
        );
38
    }
39
40
    public function logf(string $information, ...$args): void
41
    {
42
        $this->log(vsprintf(
43
            $information,
44
            $args
45
        ));
46
    }
47
}
48