Passed
Push — master ( 849c84...3dbed7 )
by Bruno
02:22
created

Renderable_bool   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 26
c 1
b 0
f 1
dl 0
loc 44
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A viewable() 0 3 1
A _editable() 0 35 3
1
<?php
2
3
namespace Formularium\Frontend\Materialize\Renderable;
4
5
use Formularium\Field;
6
use Formularium\Frontend\Materialize\RenderableMaterializeTrait;
7
use Formularium\HTMLElement;
8
9
class Renderable_bool extends \Formularium\Renderable
10
{
11
    use RenderableMaterializeTrait;
12
    
13
    public function viewable($value, Field $field, HTMLElement $previous): HTMLElement
14
    {
15
        return $previous;
16
    }
17
18
    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

18
    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...
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

18
    public function _editable($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...
19
    {
20
        $newContent = [];
21
        // add extra classes
22
        $input = $previous->get('select');
23
        $input[0]->removeAttribute('class');
24
        $id = $input[0]->getAttribute('id')[0];
25
        $newContent[] = $input[0];
26
        $label = $previous->get('label');
27
        if ($label) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $label of type Formularium\HTMLElement[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
28
            $newContent[] = $label[0];
29
        }
30
        $comment = $previous->get('div.comment');
31
        if ($comment) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $comment of type Formularium\HTMLElement[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
32
            $comment[0]->setTag('span')->setAttributes([
33
                'class' => 'helper-text',
34
                'data-error' => "wrong",
35
                'data-success' => "right"
36
            ]);
37
            $newContent[] = $comment[0];
38
        }
39
        $script = HTMLElement::factory(
40
            'script',
41
            [],
42
            "document.addEventListener('DOMContentLoaded', function() {
43
                var elems = document.querySelectorAll('#${id}');
44
                console.log(elems);
45
                var options = {};
46
                var instances = M.FormSelect.init(elems, options);
47
            });",
48
            true
49
        );
50
        $newContent[] = $script;
51
        $previous->setContent($newContent);
52
        return $previous;
53
    }
54
}
55