Completed
Push — master ( 8431a9...0bccd4 )
by Gabriel
04:28
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 0
CRAP Score 72

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 34
ccs 0
cts 21
cp 0
rs 8.4444
cc 8
nc 26
nop 1
crap 72
1
<?php
2
3
/**
4
 * Class Bootstrap4
5
 */
6
class Nip_Form_Renderer_Bootstrap4 extends Nip_Form_Renderer_Bootstrap
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

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