RendererRegistry   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 24
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRenderer() 0 9 3
A add() 0 3 1
1
<?php
2
namespace rtens\domin\delivery;
3
4
use watoki\reflect\ValuePrinter;
5
6
class RendererRegistry {
7
8
    /** @var array|Renderer[] */
9
    private $renderers = [];
10
11
    /**
12
     * @param mixed $value
13
     * @return Renderer
14
     * @throws \Exception
15
     */
16
    public function getRenderer($value) {
17
        foreach ($this->renderers as $renderer) {
18
            if ($renderer->handles($value)) {
19
                return $renderer;
20
            }
21
        }
22
23
        throw new \Exception("No Renderer found to handle " . ValuePrinter::serialize($value));
24
    }
25
26
    public function add(Renderer $renderer) {
27
        $this->renderers[] = $renderer;
28
    }
29
}