Log   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
c 1
b 0
f 1
dl 0
loc 47
ccs 0
cts 28
cp 0
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setLevel() 0 12 3
A getLevel() 0 3 1
A getLevelName() 0 7 3
A getLevelNames() 0 7 2
1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\components;
12
13
use yii\log\Logger;
14
15
/**
16
 * Log dispatcher component.
17
 */
18
class Log extends \yii\log\Dispatcher
19
{
20
    protected $_level = Logger::LEVEL_WARNING;
21
22
    protected $levels = [
23
        'error'     => Logger::LEVEL_ERROR,
24
        'warning'   => Logger::LEVEL_WARNING,
25
        'info'      => Logger::LEVEL_INFO,
26
    ];
27
28
    protected $names;
29
30
    public function setLevel($value)
31
    {
32
        if (isset($this->levels[$value])) {
33
            $this->_level = $this->levels[$value];
34
35
            return;
36
        }
37
        if (in_array($value, $this->levels, false)) {
38
            $this->_level = $value;
39
        }
40
41
        Yii::warning("wrong log level: $value");
0 ignored issues
show
Bug introduced by
The type hidev\components\Yii was not found. Did you mean Yii? If so, make sure to prefix the type with \.
Loading history...
42
    }
43
44
    public function getLevel()
45
    {
46
        return $this->_level;
47
    }
48
49
    public function getLevelName($level = null)
50
    {
51
        if ($level === null) {
52
            $level = $this->_level;
53
        }
54
55
        return isset($this->levelNames[$level]) ? $this->levelNames[$level] : null;
0 ignored issues
show
Bug Best Practice introduced by
The property levelNames does not exist on hidev\components\Log. Since you implemented __get, consider adding a @property annotation.
Loading history...
56
    }
57
58
    public function getLevelNames()
59
    {
60
        if ($this->names === null) {
61
            $this->names = array_flip($this->levels);
62
        }
63
64
        return $this->names;
65
    }
66
}
67