Passed
Push — master ( bf4e5d...29b18f )
by Bruno
06:18
created

Renderable_enum::viewable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php declare(strict_types=1); 
2
3
namespace Formularium\Frontend\Bootstrap\Renderable;
4
5
use Formularium\Datatype\Datatype_enum;
6
use Formularium\Field;
7
use Formularium\Frontend\Bootstrap\RenderableBootstrapTrait;
8
use Formularium\Frontend\HTML\Renderable\Renderable_enum as HTMLRenderable_enum;
9
use Formularium\HTMLNode;
10
11
class Renderable_enum extends \Formularium\Renderable
12
{
13
    use RenderableBootstrapTrait;
14
    
15
    public function viewable($value, Field $field, HTMLNode $previous): HTMLNode
16
    {
17
        return $previous;
18
    }
19
20
    /**
21
     * Subcall of wrapper editable() from RenderableMaterializeTrait
22
     *
23
     * @param mixed $value
24
     * @param Field $field
25
     * @param HTMLNode $previous
26
     * @return HTMLNode
27
     */
28
    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

28
    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...
29
    {
30
        $format = $field->getRenderable(HTMLRenderable_enum::FORMAT_CHOOSER, HTMLRenderable_enum::FORMAT_CHOOSER_SELECT);
31
        
32
        if ($format == HTMLRenderable_enum::FORMAT_CHOOSER_RADIO) {
33
            // add extra classes
34
            foreach ($previous->get('[type=radio]') as $input) {
35
                $input->addAttribute('class', 'custom-control-input');
36
            }
37
            foreach ($previous->get('label.formularium-radio-label') as $label) {
38
                $label->addAttribute('class', 'custom-control-label');
39
            }
40
            $radioClass = 'custom-control custom-radio';
41
            if ($field->getRenderable(HTMLRenderable_enum::LAYOUT_RADIO, HTMLRenderable_enum::LAYOUT_RADIO_INLINE)) {
42
                $radioClass = 'custom-control custom-radio custom-control-inline';
43
            }
44
            foreach ($previous->get('[class=formularium-radio-item]') as $group) {
45
                $group->addAttribute('class', $radioClass);
46
            }
47
        } else {
48
            foreach ($previous->get('select') as $input) {
49
                $input->addAttribute('class', 'custom-select');
50
            }
51
        }
52
53
        return $previous;
54
    }
55
}
56