HandlerContainerTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 46
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandlers() 0 6 1
A setHandlers() 0 5 1
A pushHandler() 0 8 2
A initHandlers() 0 6 3
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