RenderableBulmaInputTrait::viewable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Bulma;
4
5
use Formularium\Field;
6
use Formularium\Frontend\HTML\Renderable;
7
use Formularium\HTMLNode;
8
9
trait RenderableBulmaInputTrait
10
{
11
    use RenderableBulmaTrait;
12
13
    public function viewable($value, Field $field, HTMLNode $previous): HTMLNode
0 ignored issues
show
Unused Code introduced by
The parameter $field 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

13
    public function viewable($value, /** @scrutinizer ignore-unused */ 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 $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

13
    public function viewable(/** @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...
14
    {
15
        return $previous;
16
    }
17
18
    /**
19
     * Subcall of wrapper editable() from RenderableMaterializeTrait
20
     *
21
     * @param mixed $value
22
     * @param Field $field
23
     * @param HTMLNode $previous
24
     * @return HTMLNode
25
     */
26
    public function _editable($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

26
    public function _editable(/** @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...
27
    {
28
        // add extra classes
29
        $input = $previous->get('input');
30
        $input[0]->setAttributes([
31
            'class' => 'input',
32
        ]);
33
        $comment = $previous->get('.formularium-comment');
34
        if (!empty($comment)) {
35
            $comment[0]->setTag('p')->addAttributes([
36
                'class' => 'help',
37
            ]);
38
        }
39
40
        $size = $field->getRenderable(Renderable::SIZE, '');
41
        switch ($size) {
42
            case Renderable::SIZE_LARGE:
43
                $input[0]->addAttribute('class', 'is-large');
44
                break;
45
            case Renderable::SIZE_SMALL:
46
                $input[0]->addAttribute('class', 'is-small');
47
                break;
48
        }
49
        $icon = $field->getRenderable(Renderable::ICON, '');
50
        if ($icon) {
51
            $iconData = [];
52
            $iconPack = $field->getRenderable(Renderable::ICON_PACK, '');
53
            if ($iconPack) {
54
                $iconData[] = $iconPack;
55
            }
56
            $iconData[] = $icon;
57
            $iconElement = HTMLNode::factory(
58
                'span',
59
                [ 'class' => "icon is-small is-left" ],
60
                [
61
                    HTMLNode::factory(
62
                        'i',
63
                        [ 'class' => $iconData ],
64
                        []
65
                    )
66
                ]
67
            );
68
            $previous->addAttribute('class', 'has-icons-left');
69
            $previous->appendContent($iconElement);
70
        }
71
72
        return $previous;
73
    }
74
}
75