HandlerContainerTrait::getHandlers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Oqq\Minc\Log\Handler;
4
5
/**
6
 * @author Eric Braun <[email protected]>
7
 */
8
trait HandlerContainerTrait
9
{
10
    /** @var \SplStack|HandlerInterface[] */
11
    protected $handlers;
12
13
    /**
14
     * @return HandlerInterface[]
15
     */
16 3
    public function getHandlers()
17
    {
18 3
        $this->initHandlers();
19
20 3
        return $this->handlers;
21
    }
22
23
    /**
24
     * @inheritdoc
25
     */
26 15
    public function setHandlers(array $handlers)
27
    {
28 15
        $this->initHandlers(true);
29 15
        $this->pushHandler(...$handlers);
30 15
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 16
    public function pushHandler(HandlerInterface ...$handlers)
36
    {
37 16
        $this->initHandlers();
38
39 16
        foreach ($handlers as $handler) {
40 16
            $this->handlers->push($handler);
41 16
        }
42 16
    }
43
44
    /**
45
     * @param bool $reset
46
     */
47 17
    protected function initHandlers($reset = false)
48
    {
49 17
        if ($reset || null === $this->handlers) {
50 17
            $this->handlers = new \SplStack();
51 17
        }
52 17
    }
53
}
54