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

ErrorReporterStack::push()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
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
}