Passed
Push — master ( a5f3cb...7bfdd0 )
by Bruno
07:47
created

RenderableBuefyInputTrait::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 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Formularium\Frontend\Buefy;
4
5
use Formularium\Field;
6
use Formularium\Frontend\HTML\Renderable;
7
use Formularium\HTMLElement;
8
9
trait RenderableBuefyInputTrait
10
{
11
    use RenderableBuefyTrait;
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
        $previous->walk(
30
            function ($e) use ($field) {
31
                if ($e instanceof HTMLElement) {
32
                    if ($e->getTag() === 'input') {
33
                        if (($e->getAttribute('type')[0] ?? '') === 'radio') {
34
                            $e->setTag('b-radio')
35
                                ->setAttribute('native-value', $e->getAttribute('value'))
36
                                ->setContent($e->getAttribute('title'));
37
                        } else {
38
                            $e->setTag('b-input');
39
                        }
40
                    } elseif ($e->getTag() === 'select') {
41
                        $e->setTag('b-select');
42
                    } elseif ($e->getTag() === 'textarea') {
43
                        $e->setTag('b-input')->setAttribute('type', 'textarea');
44
                    } else {
45
                        return;
46
                    }
47
48
                    $size = $field->getExtension(Renderable::SIZE, '');
49
                    switch ($size) {
50
                        case Renderable::SIZE_LARGE:
51
                            $e->addAttribute('size', 'is-large');
52
                            break;
53
                        case Renderable::SIZE_SMALL:
54
                            $e->addAttribute('size', 'is-small');
55
                            break;
56
                    }
57
                }
58
            }
59
        );
60
        return $previous;
61
    }
62
}
63