Completed
Push — master ( 8431a9...0bccd4 )
by Gabriel
04:28
created

Nip_Form_Element_Input_Group   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Test Coverage

Coverage 38.24%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 28
c 1
b 0
f 0
dl 0
loc 77
ccs 13
cts 34
cp 0.3824
rs 10

9 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 getNewElement() 0 3 1
A addOption() 0 8 1
A isRequestArray() 0 3 1
A addElement() 0 6 1
A getElements() 0 3 1
1
<?php
2
3
/**
4
 * Class Nip_Form_Element_Input_Group
5
 */
6
abstract class Nip_Form_Element_Input_Group extends Nip_Form_Element_Abstract
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Deprecated Code introduced by
The class Nip_Form_Element_Abstract has been deprecated: Use Nip\Form\Elements\AbstractElement ( Ignorable by Annotation )

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

6
abstract class Nip_Form_Element_Input_Group extends /** @scrutinizer ignore-deprecated */ Nip_Form_Element_Abstract
Loading history...
7
{
8
    protected $_type = 'input_group';
9
    protected $_elements = [];
10
    protected $_values = [];
11
12
    public function isGroup()
13
    {
14
        return true;
15
    }
16
17
    public function isRequestArray()
18
    {
19
        return false;
20
    }
21
22
    public function addOptionsArray($options, $valueKey, $labelKey)
23
    {
24
        foreach ($options as $key => $option) {
25
            $option = (object) $option;
26
27
28
            $oValue    = $option->{$valueKey};
29
            $oLabel = $option->{$labelKey};
30
            $oDisabled = $option->disabled;
31
32
            if ($oDisabled) {
33
                $atribs['disabled'] = 'disabled';
34
            }
35
            $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...
36
        }
37
38
        return $this;
39
    }
40
41
    /**
42
     * @return Nip_Form_Element_Input_Group
43
     */
44 3
    public function addOption($value, $label, $attribs = [])
45
    {
46 3
        $element = $this->getNewElement();
47 3
        $element->setValue($value);
48 3
        $element->setLabel($label);
49 3
        $element->addAttribs($attribs);
50
51 3
        return $this->addElement($element);
0 ignored issues
show
Bug introduced by
$element of type Nip_Form_Element_Abstract is incompatible with the type Nip_Form_Element_Input_Abstract expected by parameter $element of Nip_Form_Element_Input_Group::addElement(). ( Ignorable by Annotation )

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

51
        return $this->addElement(/** @scrutinizer ignore-type */ $element);
Loading history...
52
    }
53
54
    /**
55
     * @return Nip_Form_Element_Abstract
56
     */
57
    public function getNewElement()
58
    {
59
        trigger_error('No new element funtion defined for this group', E_USER_ERROR);
60
    }
61
62 3
    public function addElement(Nip_Form_Element_Input_Abstract $element)
63
    {
64 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...
65 3
        $this->_elements[$key] = $element;
66 3
        $this->_values[] = $key;
67 3
        return $this;
68
    }
69
70
    public function getElement($key)
71
    {
72
        return $this->_elements[$key];
73
    }
74
75 5
    public function getElements()
76
    {
77 5
        return $this->_elements;
78
    }
79
80
    public function getValues()
81
    {
82
        return $this->_values;
83
    }
84
}
85