Passed
Push — master ( a22205...112e67 )
by Gabriel
04:04 queued 13s
created

Nip_Form_Element_Input_Group::addElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
use Nip\Form\Elements\AbstractElement;
4
5
/**
6
 * Class Nip_Form_Element_Input_Group
7
 */
8
abstract class Nip_Form_Element_Input_Group extends AbstractElement
9
{
10
    protected $_type = 'input_group';
11
    protected $_elements = [];
12
    protected $_values = [];
13
14
    /**
15
     * @return bool
16
     */
17
    public function isGroup()
18
    {
19
        return true;
20
    }
21
22
    /**
23
     * @param $options
24
     * @param $valueKey
25
     * @param $labelKey
26
     *
27
     * @return $this
28
     */
29
    public function addOptionsArray($options, $valueKey, $labelKey)
30
    {
31
        foreach ($options as $key => $option) {
32
            $option = (object)$option;
33
34
35
            $oValue    = $option->{$valueKey};
36
            $oLabel    = $option->{$labelKey};
37
            $oDisabled = $option->disabled;
38
39
            if ($oDisabled) {
40
                $atribs['disabled'] = 'disabled';
41
            }
42
            $this->addOption($oValue, $oLabel, $atribs);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $atribs does not seem to be defined for all execution paths leading up to this point.
Loading history...
43
        }
44
45
        return $this;
46
    }
47
48
    /**
49
     * @param $value
50
     * @param $label
51
     * @param array $attribs
52
     *
53
     * @return Nip_Form_Element_Input_Group
54
     */
55 3
    public function addOption($value, $label, $attribs = [])
56
    {
57 3
        $element = $this->getNewElement();
58 3
        $element->setValue($value);
59 3
        $element->setLabel($label);
60 3
        $element->addAttribs($attribs);
61
62 3
        return $this->addElement($element);
63
    }
64
65
    /**
66
     * @return AbstractElement
67
     */
68
    abstract public function getNewElement();
69
70
    /**
71
     * @param Nip_Form_Element_Input_Abstract $element
72
     *
73
     * @return $this
74
     */
75 3
    public function addElement(AbstractElement $element)
76
    {
77 3
        $key                   = $element->getValue();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $key is correct as $element->getValue() targeting Nip\Form\Elements\AbstractElement::getValue() 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...
78 3
        $this->_elements[$key] = $element;
79 3
        $this->_values[]       = $key;
80
81 3
        return $this;
82
    }
83
84
    /**
85
     * @param $key
86
     *
87
     * @return mixed
88
     */
89
    public function getElement($key)
90
    {
91
        return $this->_elements[$key];
92
    }
93
94
    /**
95
     * @return array
96
     */
97 5
    public function getElements()
98
    {
99 5
        return $this->_elements;
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function getValues()
106
    {
107
        return $this->_values;
108
    }
109
}
110