ColorField::headElements()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 3
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace rtens\domin\delivery\web\fields;
3
4
use rtens\domin\delivery\web\Element;
5
use rtens\domin\delivery\web\WebField;
6
use rtens\domin\Parameter;
7
use rtens\domin\parameters\Color;
8
use watoki\reflect\type\ClassType;
9
10 View Code Duplication
class ColorField implements WebField {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
12
    /**
13
     * @param Parameter $parameter
14
     * @return bool
15
     */
16
    public function handles(Parameter $parameter) {
17
        return $parameter->getType() == new ClassType(Color::class);
18
    }
19
20
    /**
21
     * @param Parameter $parameter
22
     * @param string $serialized
23
     * @return mixed
24
     */
25
    public function inflate(Parameter $parameter, $serialized) {
26
        return $serialized ? Color::fromHex($serialized) : null;
27
    }
28
29
    /**
30
     * @param Parameter $parameter
31
     * @param Color $value
32
     * @return string
33
     */
34
    public function render(Parameter $parameter, $value) {
35
        return (string)new Element('input', array_merge([
36
            'type' => 'color',
37
            'name' => $parameter->getName(),
38
            'value' => $value ? $value->asHex() : ''
39
        ], $parameter->isRequired() ? [
40
            'required' => 'required'
41
        ] : []));
42
    }
43
44
    /**
45
     * @param Parameter $parameter
46
     * @return array|Element[]
47
     */
48
    public function headElements(Parameter $parameter) {
49
        return [];
50
    }
51
}