Passed
Push — master ( f17b13...8bf1e0 )
by Radu
01:33
created

Items::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
namespace WebServCo\Framework\ArrayObject;
3
4
class Items
5
{
6
    protected $arrayObject;
7
8
    public function __construct(\ArrayObject $arrayObject)
9
    {
10
        $this->arrayObject = $arrayObject;
11
    }
12
13
    public function getArrayObject()
14
    {
15
        return $this->arrayObject;
16
    }
17
18
    public function set($index, $item)
19
    {
20
        $this->arrayObject->offsetSet($index, $item);
21
        return true;
22
    }
23
24
    public function remove($index)
0 ignored issues
show
Unused Code introduced by
The parameter $index is not used and could be removed. ( Ignorable by Annotation )

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

24
    public function remove(/** @scrutinizer ignore-unused */ $index)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
    {
26
        $this->arrayObject->offsetUnset();
0 ignored issues
show
Bug introduced by
The call to ArrayObject::offsetUnset() has too few arguments starting with index. ( Ignorable by Annotation )

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

26
        $this->arrayObject->/** @scrutinizer ignore-call */ 
27
                            offsetUnset();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
27
        $this->rebuildIndex();
28
        return true;
29
    }
30
31
    protected function rebuildIndex()
32
    {
33
        $data = $this->arrayObject->getArrayCopy();
34
        $this->arrayObject->exchangeArray([]);
35
        foreach ($data as $item) {
36
            $this->set(null, $item);
37
        }
38
        return true;
39
    }
40
}
41