LogLevel::shouldLogFor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VM\RequestLogger\Services;
6
7
class LogLevel
8
{
9
    public const LEVEL_DEBUG = 1;
10
    public const LEVEL_INFO = 2;
11
    public const LEVEL_NOTICE = 4;
12
    public const LEVEL_WARNING = 8;
13
    public const LEVEL_ERROR = 16;
14
    public const LEVEL_CRITICAL = 32;
15
    public const LEVEL_ALERT = 64;
16
    public const LEVEL_EMERGENCY = 128;
17
18
    private $mappings = [
19
        self::LEVEL_DEBUG => 'debug',
20
        self::LEVEL_INFO => 'info',
21
        self::LEVEL_NOTICE => 'notice',
22
        self::LEVEL_WARNING => 'warning',
23
        self::LEVEL_ERROR => 'error',
24
        self::LEVEL_CRITICAL => 'critical',
25
        self::LEVEL_ALERT => 'alert',
26
        self::LEVEL_EMERGENCY => 'emergency',
27
    ];
28
29
    private $level;
30
31 7
    public function __construct(int $level)
32
    {
33 7
        $this->level = $level;
34 7
    }
35
36 6
    public function shouldLogFor(LogLevel $right): bool
37
    {
38 6
        return $this->level <= $right->level;
39
    }
40
41 5
    public function toString(): string
42
    {
43 5
        return $this->mappings[$this->level];
44
    }
45
}
46