Completed
Push — master ( 673fc6...a88edb )
by Oleg
03:40
created

LoggerDriver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
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 41
rs 10

2 Methods

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