Passed
Push — master ( 2fa866...3020a3 )
by Bruno
07:44
created

Renderable_relationship::viewable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Frontend\HTML\Renderable;
4
5
use Formularium\Datatype;
6
use Formularium\Field;
7
use Formularium\Frontend\HTML\Framework;
8
use Formularium\Frontend\HTML\Renderable;
9
use Formularium\HTMLNode;
10
11
class Renderable_relationship extends Renderable
12
{
13
    public function viewable($value, Field $field, HTMLNode $previous): HTMLNode
14
    {
15
        return $previous;
16
    }
17
18
    public function editable($value, Field $field, HTMLNode $previous): HTMLNode
19
    {
20
        // TODO: autocomplete
21
        return $this->editableSelect($value, $field, $previous);
22
    }
23
24
    /**
25
     * @param mixed $value
26
     * @param Field $field
27
     * @param HTMLNode $previous
28
     * @return HTMLNode
29
     */
30
    public function editableSelect($value, Field $field, HTMLNode $previous): HTMLNode
0 ignored issues
show
Unused Code introduced by
The parameter $previous is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
    public function editableSelect($value, Field $field, /** @scrutinizer ignore-unused */ HTMLNode $previous): HTMLNode

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
    public function editableSelect(/** @scrutinizer ignore-unused */ $value, Field $field, HTMLNode $previous): HTMLNode

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        $input = new HTMLNode('select');
33
    
34
        $renderable = $field->getRenderables();
35
        $input->setAttributes([
36
            'id' => $field->getName() . Framework::counter(),
37
            'name' => $field->getName(),
38
            'class' => '',
39
            'data-attribute' => $field->getName(),
40
            'data-datatype' => $field->getDatatype()->getName(),
41
            'data-basetype' => $field->getDatatype()->getBasetype(),
42
            'title' => $field->getRenderable(static::LABEL, ''),
43
            'autocomplete' => 'off'
44
        ]);
45
46
        if (isset($renderable[static::PLACEHOLDER])) {
47
            $input->setAttribute('placeholder', $renderable[static::PLACEHOLDER]);
48
        }
49
        if ($field->getValidatorOption(Datatype::REQUIRED)) {
50
            $input->setAttribute('required', 'required');
51
        }
52
        /* TODO if ($validators[Datatype_association::MULTIPLE] ?? false) {
53
            $input->setAttribute('multiple', 'multiple');
54
        } */
55
        foreach ([static::DISABLED, static::READONLY] as $v) {
56
            if ($field->getRenderable($v, false)) {
57
                $input->setAttribute($v, $v);
58
            }
59
        }
60
    
61
        return $this->container($input, $field);
62
    }
63
64
    /**
65
     * @param mixed $value
66
     * @param Field $field
67
     * @param HTMLNode $previous
68
     * @return HTMLNode
69
     */
70
    public function editableAutocomplete($value, Field $field, HTMLNode $previous): HTMLNode
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

70
    public function editableAutocomplete(/** @scrutinizer ignore-unused */ $value, Field $field, HTMLNode $previous): HTMLNode

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $previous is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

70
    public function editableAutocomplete($value, Field $field, /** @scrutinizer ignore-unused */ HTMLNode $previous): HTMLNode

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
    {
72
        $input = new HTMLNode('input');
73
    
74
        $renderable = $field->getRenderables();
75
        $validators = $field->getValidators();
76
        $input->setAttributes([
77
            'id' => $field->getName() . Framework::counter(),
78
            'name' => $field->getName(),
79
            'class' => '',
80
            'data-attribute' => $field->getName(),
81
            'data-datatype' => $field->getDatatype()->getName(),
82
            'data-basetype' => $field->getDatatype()->getBasetype(),
83
            'title' => $field->getRenderable(static::LABEL, ''),
84
            'autocomplete' => 'off'
85
        ]);
86
87
        if (isset($renderable[static::PLACEHOLDER])) {
88
            $input->setAttribute('placeholder', $renderable[static::PLACEHOLDER]);
89
        }
90
        if ($validators[Datatype::REQUIRED] ?? false) {
91
            $input->setAttribute('required', 'required');
92
        }
93
        foreach ([static::DISABLED, static::READONLY] as $v) {
94
            if ($field->getRenderable($v, false)) {
95
                $input->setAttribute($v, $v);
96
            }
97
        }
98
    
99
        return $this->container($input, $field);
100
    }
101
}
102