Passed
Push — master ( 856966...11e739 )
by Oleg
03:58
created

LoggerDriver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A isSupportedLevel() 0 4 2
1
<?php /** MicroLoggerDriverInterface */
2
3
namespace Micro\Logger\Driver;
4
5
use Micro\Base\Exception;
6
use Micro\Base\IContainer;
7
use Micro\Logger\Logger;
8
9
/**
10
 * Base loggerDriver class file.
11
 *
12
 * Interface for loggers
13
 *
14
 * @author Oleg Lunegov <[email protected]>
15
 * @link https://github.com/linpax/microphp-framework
16
 * @copyright Copyright &copy; 2013 Oleg Lunegov
17
 * @license /LICENSE
18
 * @package Micro
19
 * @subpackage Logger\Driver
20
 * @version 1.0
21
 * @since 1.0
22
 */
23
abstract class LoggerDriver implements ILoggerDriver
24
{
25
    /** @var array $supportedLevels supported log levels */
26
    protected $supportedLevels = [];
27
    /** @var IContainer $container */
28
    protected $container;
29
30
31
    /**
32
     * Constructor is a initialize logger
33
     *
34
     * @access public
35
     *
36
     * @param IContainer $container Container
37
     * @param array $params configuration params
38
     *
39
     * @throws Exception
40
     * @result void
41
     */
42
    public function __construct(IContainer $container, array $params = [])
43
    {
44
        $this->container = $container;
45
46
        $levels = explode(',', str_replace(' ', '', strtolower($params['levels'])));
47
48
        foreach ($levels AS $level) {
49
            if (in_array($level, Logger::$supportedLevels, true)) {
50
                $this->supportedLevels[] = $level;
51
            }
52
        }
53
    }
54
55
    /**
56
     * Check support level
57
     *
58
     * @access public
59
     *
60
     * @param integer $level level number
61
     *
62
     * @return bool
63
     */
64
    public function isSupportedLevel($level)
65
    {
66
        return in_array($level, $this->supportedLevels, false) === false ?: true;
67
    }
68
}
69