Passed
Push — master ( d764eb...5a8560 )
by Bruno
06:29
created

Renderable_choice::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\Bootstrap\Renderable;
4
5
use Formularium\Datatype\Datatype_choice;
6
use Formularium\Field;
7
use Formularium\Frontend\Bootstrap\RenderableBootstrapTrait;
8
use Formularium\Frontend\HTML\Renderable\Renderable_choice as HTMLRenderable_choice;
9
use Formularium\HTMLElement;
10
11
class Renderable_choice extends \Formularium\Renderable
12
{
13
    use RenderableBootstrapTrait;
14
    
15
    public function viewable($value, Field $field, HTMLElement $previous): HTMLElement
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 HTMLElement $previous
26
     * @return HTMLElement
27
     */
28
    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

28
    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...
29
    {
30
        $format = $field->getExtension(HTMLRenderable_choice::FORMAT_CHOOSER, HTMLRenderable_choice::FORMAT_CHOOSER_SELECT);
31
        
32
        if ($format == HTMLRenderable_choice::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') as $label) {
38
                $label->addAttribute('class', 'custom-control-label');
39
            }
40
            $radioClass = 'custom-control custom-radio';
41
            if ($field->getExtension(HTMLRenderable_choice::LAYOUT_RADIO, HTMLRenderable_choice::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