renderChildElement()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 1
crap 2.0625
1
<?php
2
3
use Nip_Form_Element_Checkbox as Checkbox;
4
use Nip_Form_Element_Input_Abstract as AbstractInput;
5
6
/**
7
 * Class Nip_Form_Renderer_Elements_Input_Group
8
 * @method Nip_Form_Element_Input_Group getElement()
9
 */
10
abstract class Nip_Form_Renderer_Elements_Input_Group extends Nip_Form_Renderer_Elements_Input_Abstract
11
{
12
    protected $_separator = '<br />';
13
14
    /** @noinspection PhpMissingParentCallCommonInspection
15
     * @return string
16
     */
17 5
    public function generateElement()
18
    {
19 5
        $elements = $this->getElement()->getElements();
20 5
        $returnElements = [];
21 5
        $return = '';
22 5
        foreach ($elements as $element) {
23 3
            $returnElements[] = $this->renderChildElement($element);
24
        }
25 5
        $return .= implode($this->getSeparator(), $returnElements);
26
27 5
        return $return;
28
    }
29
30
    /**
31
     * @param AbstractInput|Checkbox $element
32
     * @return mixed
33
     */
34 3
    public function renderChildElement($element)
35
    {
36 3
        if ($element->getValue() == $this->getElement()->getValue()) {
37
            $element->setChecked(true);
0 ignored issues
show
Bug introduced by
The method setChecked() does not exist on Nip_Form_Element_Input_Abstract. It seems like you code against a sub-type of Nip_Form_Element_Input_Abstract such as Nip_Form_Element_Radio or Nip_Form_Element_Checkbox. ( Ignorable by Annotation )

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

37
            $element->/** @scrutinizer ignore-call */ 
38
                      setChecked(true);
Loading history...
38
        }
39
40 3
        return $element->render();
41
    }
42
43
    /**
44
     * @return string
45
     */
46 5
    public function getSeparator()
47
    {
48 5
        return $this->_separator;
49
    }
50
51
    /**
52
     * @param $separator
53
     * @return $this
54
     */
55
    public function setSeparator($separator)
56
    {
57
        $this->_separator = $separator;
58
59
        return $this;
60
    }
61
}
62