Completed
Push — master ( 6d5c70...e9ec54 )
by Markus
02:46
created

RendererRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
namespace Mathielen\ReportWriteEngine\Engine;
3
4
use Mathielen\ReportWriteEngine\Engine\Renderer\RendererInterface;
5
6
class RendererRepository
7
{
8
9
    /**
10
     * @var array
11
     */
12
    private $reportConfig;
13
14
    /**
15
     * @var array
16
     */
17
    private $renderer = [];
18
19
    public function __construct(array $reportConfig = [])
20
    {
21
        $this->reportConfig = $reportConfig;
22
    }
23
24
    /**
25
     * @return $this
26
     */
27
    public function setConfig(array $reportConfig = [])
28
    {
29
        $this->reportConfig = $reportConfig;
30
31
        return $this;
32
    }
33
34
    /**
35
     * @return $this
36
     */
37
    public function add($orientation, RendererInterface $renderer)
38
    {
39
        $this->renderer[$orientation] = $renderer;
40
41
        return $this;
42
    }
43
44
    /**
45
     * @return RendererInterface
46
     */
47
    public function getRendererForNode($nodeId)
48
    {
49
        $orientation = isset($this->reportConfig[$nodeId]) ? $this->reportConfig[$nodeId] : RendererInterface::ORIENTATION_VERTICAL;
50
        if (!isset($this->renderer[$orientation])) {
51
            throw new \RuntimeException("Could not find writer for orientation $orientation");
52
        }
53
54
        return $this->renderer[$orientation];
55
    }
56
57
}
58