Passed
Push — master ( bd72d4...a51a38 )
by 世昌
02:21
created

LogLevel::compare()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\component\debug\log;
3
4
/**
5
 * 日志等级
6
 */
7
class LogLevel
8
{
9
    const EMERGENCY = 'emergency';
10
    const ALERT     = 'alert';
11
    const CRITICAL  = 'critical';
12
    const ERROR     = 'error';
13
    const WARNING   = 'warning';
14
    const NOTICE    = 'notice';
15
    const INFO      = 'info';
16
    const DEBUG     = 'debug';
17
18
    protected static $levels = ['debug', 'info', 'notice', 'warning', 'error', 'critical', 'alert', 'emergency'];
19
    
20
    /**
21
     * 比较优先级
22
     *
23
     * @param string $a
24
     * @param string $b
25
     * @return integer
26
     */
27
    public static function compare(string $a, string $b): int
28
    {
29
        $indexA = array_search($a, static::$levels);
30
        $indexB = array_search($b, static::$levels);
31
        return $indexA - $indexB;
32
    }
33
}
34