Nip_Form_Renderer_List::renderElements()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 15
ccs 0
cts 10
cp 0
rs 9.9666
cc 3
nc 4
nop 0
crap 12
1
<?php
2
3
use Nip\Form\Renderer\AbstractRenderer;
4
5
class Nip_Form_Renderer_List extends AbstractRenderer
6
{
7
    protected $_list = [];
8
9
    public function setListAttrib($type, $value)
10
    {
11
        $this->_list[$type] = $value;
12
13
        return $this;
14
    }
15
16
    public function addClassName($name)
17
    {
18
        $this->_list['class'] .= ' ' . $name;
19
20
        return $this;
21
    }
22
23
    public function renderElements()
24
    {
25
        $return = '<ul';
26
        foreach ($this->_list as $attrib => $value) {
27
            $return .= ' ' . $attrib . '="' . $value . '"';
28
        }
29
        $return .= '>';
30
31
        $renderRows = $this->renderRows();
32
        if ($renderRows) {
33
            $return .= $renderRows;
34
        }
35
        $return .= '</ul>';
36
37
        return $return;
38
    }
39
40
    public function renderRows()
41
    {
42
        $elements = $this->getElements();
43
        $return = '';
44
        foreach ($elements as $element) {
45
            if (!$element->isRendered()) {
46
                $return .= '<li class="row">';
47
48
                $return = $this->renderLabel($element);
0 ignored issues
show
Deprecated Code introduced by
The function Nip\Form\Renderer\AbstractRenderer::renderLabel() has been deprecated: Use renderElementLabel() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

48
                $return = /** @scrutinizer ignore-deprecated */ $this->renderLabel($element);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
49
50
                $class = "value " . ($element->getType() == 'input' ? 'input' : '');
51
                $return .= '<span class="' . $class . '">';
52
                $return .= $element->renderElement();
53
                $return .= '</span>';
54
55
                $return .= $element->renderErrors();
56
57
                $return .= '</li>';
58
            }
59
        }
60
61
        return $return;
62
    }
63
}
64