AbstractHandler::canNotify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Tleckie\Log\Handler;
4
5
use Psr\Log\AbstractLogger;
6
use Tleckie\Log\Level;
7
8
/**
9
 * Class AbstractHandler
10
 *
11
 * @package Tleckie\Log\Handler
12
 * @author  Teodoro Leckie Westberg <[email protected]>
13
 */
14
abstract class AbstractHandler extends AbstractLogger
15
{
16
    /** @var array */
17
    protected const LEVELS = [
18
        Level::EMERGENCY => 0,
19
        Level::ALERT => 1,
20
        Level::CRITICAL => 2,
21
        Level::ERROR => 3,
22
        Level::WARNING => 4,
23
        Level::NOTICE => 5,
24
        Level::INFO => 6,
25
        Level::DEBUG => 7
26
    ];
27
28
    /** @var string */
29
    protected string $minimumLevel;
30
31
    /**
32
     * AbstractHandler constructor.
33
     *
34
     * @param string $minimumLevel
35
     */
36
    public function __construct(string $minimumLevel = Level::DEBUG)
37
    {
38
        $this->minimumLevel = $minimumLevel;
39
    }
40
41
    /**
42
     * @param string $level
43
     * @return bool
44
     */
45
    protected function canNotify(string $level): bool
46
    {
47
        return static::LEVELS[$this->minimumLevel] >= static::LEVELS[$level];
48
    }
49
}
50