Passed
Push — master ( 648548...5e4c5e )
by Bruno
08:25
created

RenderableBootstrapvueInputTrait::_editable()   B

Complexity

Conditions 8
Paths 1

Size

Total Lines 47
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 8
eloc 25
c 1
b 0
f 1
nc 1
nop 3
dl 0
loc 47
rs 8.4444
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\Bootstrapvue;
4
5
use Formularium\Field;
6
use Formularium\Frontend\HTML\Renderable;
7
use Formularium\HTMLNode;
8
9
trait RenderableBootstrapvueInputTrait
10
{
11
    use RenderableBootstrapvueTrait;
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
        $previous->walk(
30
            function ($e) use ($field) {
31
                if ($e instanceof HTMLNode) {
32
                    if ($e->getTag() === 'input') {
33
                        // TODO: form-group
34
                        if (($e->getAttribute('type')[0] ?? '') === 'radio') {
35
                            $e->setTag('b-form-radio')
36
                                ->setAttribute('native-value', $e->getAttribute('value'))
37
                                ->setContent($e->getAttribute('title'));
38
                        } else {
39
                            $e->setTag('b-form-input');
40
                        }
41
                    } elseif ($e->getTag() === 'select') {
42
                        $e->setTag('b-form-select');
43
                    } elseif ($e->getTag() === 'textarea') {
44
                        $e->setTag('b-form-textarea');
45
                    } else {
46
                        return;
47
                    }
48
49
                    $size = $field->getRenderable(Renderable::SIZE, '');
50
                    switch ($size) {
51
                        case Renderable::SIZE_LARGE:
52
                            $e->addAttribute('size', 'large');
53
                            break;
54
                        case Renderable::SIZE_SMALL:
55
                            $e->addAttribute('size', 'small');
56
                            break;
57
                    }
58
59
                    /* TODO
60
                    $icon = $field->getRenderable(Renderable::ICON, '');
61
                    if ($icon) {
62
                        $e->addAttribute('icon', str_replace('fa-', '', $icon));
63
                    }
64
                    $iconPack = $field->getRenderable(Renderable::ICON_PACK, '');
65
                    if ($iconPack) {
66
                        $e->addAttribute('icon-pack', $iconPack);
67
                    }
68
                    */
69
                }
70
            }
71
        );
72
        return $previous;
73
    }
74
}
75