ErrorReporterAggregate::push()   A
last analyzed

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
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Debug;
4
5
use IteratorAggregate;
6
use Throwable;
7
use Venta\Contracts\Container\Container;
8
use Venta\Contracts\Debug\ErrorReporter;
9
use Venta\Contracts\Debug\ErrorReporterAggregate as ErrorReporterStackContract;
10
11
/**
12
 * Class ErrorReporterStack
13
 *
14
 * @package Venta\Debug
15
 */
16
final class ErrorReporterAggregate implements IteratorAggregate, ErrorReporterStackContract
17
{
18
    /**
19
     * @var Container
20
     */
21
    private $container;
22
23
    /**
24
     * @var string[]
25
     */
26
    private $reporterClasses = [];
27
28
    /**
29
     * ErrorReporterStack constructor.
30
     *
31
     * @param Container $container
32
     */
33 1
    public function __construct(Container $container)
34
    {
35 1
        $this->container = $container;
36 1
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function getIterator()
42
    {
43
        foreach (array_unique($this->reporterClasses) as $reporter) {
44
            yield $this->container->get($reporter);
45
        }
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51
    public function push(string $reporterClass): ErrorReporterStackContract
52
    {
53
        array_unshift($this->reporterClasses, $reporterClass);
54
55
        return $this;
56
    }
57
58
    /**
59
     * @inheritDoc
60
     */
61
    public function report(Throwable $e)
62
    {
63
        /** @var ErrorReporter $reporter */
64
        foreach ($this->getIterator() as $reporter) {
65
            $reporter->report($e);
66
        }
67
    }
68
69
}