Issues (138)

src/Renderer/Bootstrap4.php (2 issues)

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