Passed
Branch master (2f08da)
by Stanislau
24:28 queued 21:51
created

LogLevel::getLevelFromString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
ccs 12
cts 12
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Plugin\Logger\Configuration;
15
16
use Psr\Log\LogLevel as PsrLogLevel;
17
18
enum LogLevel
19
{
20
    case DEBUG;
21
    case CRITICAL;
22
    case EMERGENCY;
23
    case ALERT;
24
    case ERROR;
25
    case INFO;
26
    case WARNING;
27
    case NOTICE;
28
29 1
    public function level(): string
30
    {
31 1
        return match ($this) {
32 1
            LogLevel::DEBUG => PsrLogLevel::DEBUG,
33 1
            LogLevel::CRITICAL => PsrLogLevel::CRITICAL,
34 1
            LogLevel::EMERGENCY => PsrLogLevel::EMERGENCY,
35 1
            LogLevel::ALERT => PsrLogLevel::ALERT,
36 1
            LogLevel::ERROR => PsrLogLevel::ERROR,
37 1
            LogLevel::INFO => PsrLogLevel::INFO,
38 1
            LogLevel::WARNING => PsrLogLevel::WARNING,
39 1
            LogLevel::NOTICE => PsrLogLevel::NOTICE,
40 1
        };
41
    }
42
43 5
    public static function getLevelFromString(string $logLevel): LogLevel
44
    {
45 5
        $toLower = mb_strtolower($logLevel);
46
47 5
        return match ($toLower) {
48 5
            PsrLogLevel::DEBUG => LogLevel::DEBUG,
49 5
            PsrLogLevel::CRITICAL => LogLevel::CRITICAL,
50 5
            PsrLogLevel::EMERGENCY => LogLevel::EMERGENCY,
51 5
            PsrLogLevel::ALERT => LogLevel::ALERT,
52 5
            PsrLogLevel::ERROR => LogLevel::ERROR,
53 5
            PsrLogLevel::INFO => LogLevel::INFO,
54 5
            PsrLogLevel::WARNING => LogLevel::WARNING,
55 5
            PsrLogLevel::NOTICE => LogLevel::NOTICE,
56 5
            default => throw new \RuntimeException(sprintf('Invalid log level value `%s`.', $logLevel)),
57 5
        };
58
    }
59
}
60