Completed
Push — master ( 3b2a6f...c50757 )
by Nikolas
05:45
created

TextField::inflate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 3
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 3
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php namespace rtens\domin\delivery\web\fields;
2
3
use rtens\domin\delivery\web\Element;
4
use rtens\domin\delivery\web\WebField;
5
use rtens\domin\Parameter;
6
use rtens\domin\parameters\Text;
7
use watoki\reflect\type\ClassType;
8
9 View Code Duplication
class TextField 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...
10
11
    /**
12
     * @param Parameter $parameter
13
     * @return bool
14
     */
15
    public function handles(Parameter $parameter) {
16
        return $parameter->getType() == new ClassType(Text::class);
17
    }
18
19
    /**
20
     * @param Parameter $parameter
21
     * @param string $serialized
22
     * @return mixed
23
     */
24
    public function inflate(Parameter $parameter, $serialized) {
25
        return new Text($serialized);
26
    }
27
28
    /**
29
     * @param Parameter $parameter
30
     * @param Text $value
31
     * @return string
32
     */
33
    public function render(Parameter $parameter, $value) {
34
        return (string)new Element('textarea', array_merge([
35
            'name' => $parameter->getName(),
36
            'class' => 'form-control',
37
        ], $parameter->isRequired() ? [
38
            'required' => 'required'
39
        ] : []), [
40
            $value ? $value->getContent() : null
41
        ]);
42
    }
43
44
    /**
45
     * @param Parameter $parameter
46
     * @return array|\rtens\domin\delivery\web\Element[]
47
     */
48
    public function headElements(Parameter $parameter) {
49
        return [];
50
    }
51
}