CascadeHandler::write()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
cc 3
eloc 4
nc 3
nop 1
crap 12
1
<?php
2
3
namespace Oqq\Minc\Log\Handler;
4
5
use Oqq\Minc\Log\Record;
6
7
/**
8
 * @author Eric Braun <[email protected]>
9
 */
10
class CascadeHandler extends AbstractHandler implements HandlerContainerInterface
11
{
12
    use HandlerContainerTrait;
13
14
    /**
15
     * @param HandlerInterface[] $handlers
16
     * @param int $level
17
     * @param bool $pass
18
     */
19
    public function __construct(
20
        array $handlers,
21
        $level = HandlerInterface::DEFAULT_LEVEL,
22
        $pass = HandlerInterface::DEFAULT_PASS
23
    ) {
24
        parent::__construct($level, $pass);
25
26
        $this->setHandlers($handlers);
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function isHandling(Record $record)
33
    {
34
        if (!parent::isHandling($record)) {
35
            return false;
36
        }
37
38
        foreach ($this->getHandlers() as $handler) {
39
            if ($handler->isHandling($record)) {
40
                return true;
41
            }
42
        }
43
44
        return false;
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50
    protected function write(Record $record)
51
    {
52
        foreach ($this->getHandlers() as $handler) {
53
            if ($handler->isHandling($record)) {
54
                $handler->handle($record);
55
            }
56
        }
57
    }
58
}
59