AbstractHandler   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 44%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 10
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 87
ccs 11
cts 25
cp 0.44
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getLevel() 0 4 1
A setLevel() 0 4 1
A isPass() 0 4 1
A setPass() 0 4 1
A isHandling() 0 4 1
A handle() 0 16 4
write() 0 1 ?
1
<?php
2
3
namespace Oqq\Minc\Log\Handler;
4
5
use Oqq\Minc\Log\Formatter\FormatterContainerInterface;
6
use Oqq\Minc\Log\Formatter\FormatterContainerTrait;
7
use Oqq\Minc\Log\Processor\ProcessorContainerInterface;
8
use Oqq\Minc\Log\Record;
9
10
/**
11
 * @author Eric Braun <[email protected]>
12
 */
13
abstract class AbstractHandler implements HandlerInterface, FormatterContainerInterface
14
{
15
    use FormatterContainerTrait;
16
17
    /** @var int */
18
    protected $level;
19
20
    /** @var bool */
21
    protected $pass;
22
23
    /**
24
     * @param int $level
25
     * @param bool $pass
26
     */
27 14
    public function __construct($level = HandlerInterface::DEFAULT_LEVEL, $pass = HandlerInterface::DEFAULT_PASS)
28
    {
29 14
        $this->level = $level;
30 14
        $this->pass = $pass;
31 14
    }
32
33
    /**
34
     * @return int
35
     */
36
    public function getLevel()
37
    {
38
        return $this->level;
39
    }
40
41
    /**
42
     * @param int $level
43
     */
44
    public function setLevel($level)
45
    {
46
        $this->level = $level;
47
    }
48
49
    /**
50
     * @return bool
51
     */
52
    public function isPass()
53
    {
54
        return $this->pass;
55
    }
56
57
    /**
58
     * @param bool $pass
59
     */
60
    public function setPass($pass)
61
    {
62
        $this->pass = $pass;
63
    }
64
65
    /**
66
     * @inheritdoc
67
     */
68 12
    public function isHandling(Record $record)
69
    {
70 12
        return $this->level <= $record->getLevel()->getValue();
71
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76 12
    public function handle(Record $record)
77
    {
78 12
        if (!$this->isHandling($record)) {
79
            return true;
80
        }
81
82 12
        if ($this instanceof ProcessorContainerInterface) {
83
            $this->applyProcessors($record);
0 ignored issues
show
Bug introduced by
The method applyProcessors() does not seem to exist on object<Oqq\Minc\Log\Handler\AbstractHandler>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
        }
85
86 12
        if (false === $this->write($record)) {
87
            return true;
88
        }
89
90 12
        return $this->pass;
91
    }
92
93
    /**
94
     * @param Record $record
95
     *
96
     * @return null|false
97
     */
98
    abstract protected function write(Record $record);
99
}
100