Passed
Push — master ( bf9442...0c219f )
by Bruno
06:29
created

RenderableBootstrapInputTrait::viewable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 3
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Bootstrap;
4
5
use Formularium\Field;
6
use Formularium\Frontend\HTML\Renderable;
7
use Formularium\HTMLElement;
8
9
trait RenderableBootstrapInputTrait
10
{
11
    use RenderableBootstrapTrait;
12
13
    public function viewable($value, Field $field, HTMLElement $previous): HTMLElement
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, HTMLElement $previous): HTMLElement

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, HTMLElement $previous): HTMLElement

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 HTMLElement $previous
24
     * @return HTMLElement
25
     */
26
    public function _editable($value, Field $field, HTMLElement $previous): HTMLElement
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, HTMLElement $previous): HTMLElement

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')[0];
30
        $input->addAttributes([
31
            'class' => 'form-control',
32
        ]);
33
        $comment = $previous->get('.formularium-comment');
34
        if (!empty($comment)) {
35
            $comment[0]->setTag('small')->addAttributes([
36
                'class' => 'form-text text-muted',
37
            ]);
38
        }
39
        $size = $field->getExtension(Renderable::SIZE, '');
40
        switch ($size) {
41
            case Renderable::SIZE_LARGE:
42
                $input->addAttribute('class', 'form-control-lg');
43
                break;
44
            case Renderable::SIZE_SMALL:
45
                $input->addAttribute('class', 'form-control-sm');
46
                break;
47
        }
48
49
        $icon = $field->getExtension(Renderable::ICON, '');
50
        if ($icon) {
51
            $iconData = [];
52
            $iconPack = $field->getExtension(Renderable::ICON_PACK, '');
53
            if ($iconPack) {
54
                $iconData[] = $iconPack;
55
            }
56
            $iconData[] = $icon;
57
            $group = HTMLElement::factory(
58
                'div',
59
                [ 'class' => "input-group mb-3" ],
60
                [
61
                    HTMLElement::factory(
62
                        'div',
63
                        [ 'class' => "input-group-prepend" ],
64
                        HTMLElement::factory(
65
                            'span',
66
                            [ 'class' => "input-group-text" ],
67
                            HTMLElement::factory(
68
                                'i',
69
                                [ 'class' => $iconData ],
70
                                []
71
                            )
72
                        )
73
                    ),
74
                    clone $input
75
                ]
76
            );
77
            $input->replace($group);
78
        }
79
80
        return $previous;
81
    }
82
}
83