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

Nip_Form_Element_MultiElement::addElement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
class Nip_Form_Element_MultiElement 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

3
class Nip_Form_Element_MultiElement extends /** @scrutinizer ignore-deprecated */ Nip_Form_Element_Abstract
Loading history...
4
{
5
    protected $_type = 'multiElement';
6
7
    /**
8
     * @var Nip_Form_Element_Abstract[]
9
     */
10
    protected $elements = [];
11
12
    /**
13
     * @param Nip_Form_Element_Abstract $element
14
     * @return $this
15
     */
16
    public function addElement(Nip_Form_Element_Abstract $element)
17
    {
18
        $key = $element->getName();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $key is correct as $element->getName() targeting Nip\Form\Elements\AbstractElement::getName() 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...
19
        $this->elements[$key] = $element;
20
        return $this;
21
    }
22
23
    /**
24
     * @return Nip_Form_Element_Abstract[]
25
     */
26 1
    public function getElements()
27
    {
28 1
        reset($this->elements);
29 1
        return $this->elements;
30
    }
31
32
    /**
33
     * @param $name
34
     * @return Nip_Form_Element_Abstract
35
     * @throws \Nip\Logger\Exception
36
     */
37
    public function getElement($name)
38
    {
39
        if ($this->hasElement($name)) {
40
            return $this->elements[$name];
41
        }
42
        throw new \Nip\Logger\Exception("Invalid child element");
0 ignored issues
show
Bug introduced by
The type Nip\Logger\Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
    }
44
45
    /**
46
     * @param $name
47
     * @return bool
48
     */
49
    public function hasElement($name)
50
    {
51
        return isset($this->elements[$name]);
52
    }
53
}
54