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

RendererRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 52
ccs 0
cts 22
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setConfig() 0 6 1
A add() 0 6 1
A getRendererForNode() 0 9 3
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