ColorRenderer::handles()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace rtens\domin\delivery\web\renderers;
3
4
use rtens\domin\delivery\web\Element;
5
use rtens\domin\delivery\web\WebRenderer;
6
use rtens\domin\parameters\Color;
7
8
class ColorRenderer implements WebRenderer {
9
10
    /**
11
     * @param mixed $value
12
     * @return bool
13
     */
14
    public function handles($value) {
15
        return $value instanceof Color;
16
    }
17
18
    /**
19
     * @param Color $value
20
     * @return mixed
21
     */
22
    public function render($value) {
23
        if (!$value) {
24
            return null;
25
        }
26
27
        return (string)new Element('span', [
28
            'style' => 'padding: 2pt 6pt; background-color: ' . $value->asHex()
29
        ], [$value->asHex()]);
30
    }
31
32
    /**
33
     * @param mixed $value
34
     * @return array|Element[]
35
     */
36
    public function headElements($value) {
37
        return [];
38
    }
39
}