Passed
Push — master ( c3f58e...a22205 )
by Gabriel
13:48 queued 12s
created

Nip_Form_Renderer_Bootstrap4::renderRow()   B

Complexity

Conditions 8
Paths 26

Size

Total Lines 34
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 34
ccs 5
cts 5
cp 1
rs 8.4444
cc 8
nc 26
nop 1
crap 8
1
<?php
2
3
/**
4
 * Class Bootstrap4
5
 */
6
class Nip_Form_Renderer_Bootstrap4 extends Nip_Form_Renderer_Bootstrap
7
{
8
    /**
9
     * @param Nip_Form_Element_Abstract $element
10
     * @return string
11
     */
12 1
    public function renderRow($element)
13
    {
14 1
        $return = '';
15 1
        if (!$element->isRendered()) {
16 1
            if ($element->hasCustomRenderer()) {
17
                return $element->render();
18 1
            }
19
20
            $return .= '<div class="form-group row row-'.$element->getUniqueId().($element->isError() ? ' has-error' : '').'">';
21
22
            $renderLabel = $element->getOption('render_label');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $renderLabel is correct as $element->getOption('render_label') targeting Nip\Form\Elements\AbstractElement::getOption() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
23
            if ($renderLabel !== false) {
0 ignored issues
show
introduced by
The condition $renderLabel !== false is always true.
Loading history...
24
                $return .= $this->renderLabel($element);
25
            }
26
27
            $class = '';
28
            if ($this->getForm()->hasClass('form-horizontal')) {
29
                $class = $element->getType() == 'checkbox' ? 'col-sm-offset-3 col-sm-9' : 'col-sm-9';
30
            }
31
32
            $return .= '<div class="'.$class.'">';
33
            $return .= $this->renderElement($element);
34
35
            $helpBlock = $element->getOption('form-help');
36
            if ($helpBlock) {
37
                $return .= '<span class="help-block">'.$helpBlock.'</span>';
38
            }
39
40
            $return .= $element->renderErrors();
41
            $return .= '</div>';
42
            $return .= '</div>';
43
        }
44
45
        return $return;
46
    }
47
48
    /**
49
     * @param $label
50
     * @param bool $required
51
     * @param bool $error
52
     * @return string
53
     */
54
    public function renderLabel($label, $required = false, $error = false)
55
    {
56
        if (is_object($label)) {
57
            $element = $label;
58
            $label = $element->getLabel();
59
            $required = $element->isRequired();
60
            $error = $element->isError();
61
        }
62
63
        $return = '<label class="col-form-label '.($this->getForm()->hasClass('form-horizontal') ? ' col-sm-3' : '').($error ? '' : '').'">';
64
        $return .= $label.':';
65
66
        if ($required) {
67
            $return .= '<span class="required">*</span>';
68
        }
69
70
        $return .= "</label>";
71
72
        return $return;
73
    }
74
}
75