Passed
Push — master ( 8bc538...1c53d0 )
by Vsevolods
08:57
created

ErrorReporterStack   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 20%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 43
ccs 3
cts 15
cp 0.2
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIterator() 0 6 2
A push() 0 6 1
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Debug;
4
5
use IteratorAggregate;
6
use Venta\Contracts\Container\Container;
7
use Venta\Contracts\Debug\ErrorReporterStack as ErrorReporterStackContract;
8
9
/**
10
 * Class ErrorReporterStack
11
 *
12
 * @package Venta\Debug
13
 */
14
final class ErrorReporterStack implements IteratorAggregate, ErrorReporterStackContract
15
{
16
    /**
17
     * @var Container
18
     */
19
    private $container;
20
21
    /**
22
     * @var string[]
23
     */
24
    private $reporterClasses = [];
25
26
    /**
27
     * ErrorReporterStack constructor.
28
     *
29
     * @param Container $container
30
     */
31 1
    public function __construct(Container $container)
32
    {
33 1
        $this->container = $container;
34 1
    }
35
36
    /**
37
     * @inheritDoc
38
     */
39
    public function getIterator()
40
    {
41
        foreach (array_unique($this->reporterClasses) as $reporter) {
42
            yield $this->container->get($reporter);
43
        }
44
    }
45
46
    /**
47
     * @inheritDoc
48
     */
49
    public function push(string $reporterClass): ErrorReporterStackContract
50
    {
51
        array_unshift($this->reporterClasses, $reporterClass);
52
53
        return $this;
54
    }
55
56
}