Passed
Push — master ( b8e171...9e4d7b )
by Gabriel
04:14 queued 12s
created

Nip_Form_Element_Input_Group   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Test Coverage

Coverage 41.94%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 27
c 1
b 0
f 0
dl 0
loc 108
ccs 13
cts 31
cp 0.4194
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A isGroup() 0 3 1
A getElement() 0 3 1
A addOptionsArray() 0 17 3
A getValues() 0 3 1
A addOption() 0 8 1
A isRequestArray() 0 3 1
A addElement() 0 7 1
A getElements() 0 3 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
     * @return bool
24
     */
25
    public function isRequestArray()
26
    {
27
        return false;
28
    }
29
30
    /**
31
     * @param $options
32
     * @param $valueKey
33
     * @param $labelKey
34
     *
35
     * @return $this
36
     */
37
    public function addOptionsArray($options, $valueKey, $labelKey)
38
    {
39
        foreach ($options as $key => $option) {
40
            $option = (object)$option;
41
42
43
            $oValue    = $option->{$valueKey};
44
            $oLabel    = $option->{$labelKey};
45
            $oDisabled = $option->disabled;
46
47
            if ($oDisabled) {
48
                $atribs['disabled'] = 'disabled';
49
            }
50
            $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...
51
        }
52
53
        return $this;
54
    }
55
56
    /**
57
     * @param $value
58
     * @param $label
59
     * @param array $attribs
60
     *
61
     * @return Nip_Form_Element_Input_Group
62
     */
63 3
    public function addOption($value, $label, $attribs = [])
64
    {
65 3
        $element = $this->getNewElement();
66 3
        $element->setValue($value);
67 3
        $element->setLabel($label);
68 3
        $element->addAttribs($attribs);
69
70 3
        return $this->addElement($element);
71
    }
72
73
    /**
74
     * @return AbstractElement
75
     */
76
    abstract public function getNewElement();
77
78
    /**
79
     * @param Nip_Form_Element_Input_Abstract $element
80
     *
81
     * @return $this
82
     */
83 3
    public function addElement(AbstractElement $element)
84
    {
85 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...
86 3
        $this->_elements[$key] = $element;
87 3
        $this->_values[]       = $key;
88
89 3
        return $this;
90
    }
91
92
    /**
93
     * @param $key
94
     *
95
     * @return mixed
96
     */
97
    public function getElement($key)
98
    {
99
        return $this->_elements[$key];
100
    }
101
102
    /**
103
     * @return array
104
     */
105 5
    public function getElements()
106
    {
107 5
        return $this->_elements;
108
    }
109
110
    /**
111
     * @return array
112
     */
113
    public function getValues()
114
    {
115
        return $this->_values;
116
    }
117
}
118