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

PirateLogger::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 2
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 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