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

Renderable_enum   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 20
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A viewable() 0 3 1
A _editable() 0 29 5
1
<?php declare(strict_types=1); 
2
3
namespace Formularium\Frontend\Bulma\Renderable;
4
5
use Formularium\Datatype\Datatype_enum;
6
use Formularium\Field;
7
use Formularium\Frontend\Bulma\RenderableBulmaTrait;
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 RenderableBulmaTrait;
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
            $labels = [];
34
            // add extra classes
35
            foreach ($previous->get('.formularium-radio-item') as $container) {
36
                $label = $container->get('label')[0];
37
                $input = $container->get('input')[0];
38
                $labels[] = $label->prependContent($input)->addAttribute('class', 'radio');
39
            }
40
            $previous->get('.formularium-radio-group')[0]->setContent($labels);
41
        } else {
42
            // create a div around the old select
43
            $oldSelect = $previous->get('select')[0];
44
            $newSelect = clone $oldSelect;
45
            $oldSelect->setTag('div')->setAttribute('class', 'select')->setContent($newSelect);
46
        }
47
48
        foreach ($previous->getContent() as $e) {
49
            if ($e->getAttribute('class') === ['formularium-comment']) {
50
                $e->setTag('p')->setAttributes([
51
                    'class' => 'help',
52
                ]);
53
            }
54
        }
55
56
        return $previous;
57
    }
58
}
59