Completed
Push — master ( 33d412...b764b5 )
by Ben
02:26
created

ArrayCollection::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Thinktomorrow\Vine\Branch;
4
5
use ArrayAccess;
6
use ArrayIterator;
7
use Countable;
8
use IteratorAggregate;
9
10
/**
11
 * Class Collection
12
 *
13
 * @property array $branches
14
 */
15
class ArrayCollection implements ArrayAccess, Countable, IteratorAggregate
16
{
17
    protected $branches = [];
18
19 9
    public function offsetSet($offset, $value) {
20 9
        if (is_null($offset)) {
21 9
            $this->branches[] = $value;
22 6
        } else {
23
            $this->branches[$offset] = $value;
24
        }
25 9
    }
26
27 3
    public function offsetExists($offset) {
28 3
        return isset($this->branches[$offset]);
29
    }
30
31
    public function offsetUnset($offset) {
32
        unset($this->branches[$offset]);
33
    }
34
35 24
    public function offsetGet($offset) {
36 24
        return isset($this->branches[$offset]) ? $this->branches[$offset] : null;
37
    }
38
39 27
    public function count()
40
    {
41 27
        return count($this->branches);
42
    }
43
44
    /**
45
     * Iterator for the branches
46
     *
47
     * @return \ArrayIterator
48
     */
49 30
    public function getIterator()
50
    {
51 30
        return new ArrayIterator($this->branches);
52
    }
53
54 6
    public function toArray()
55
    {
56 6
        return BuildArray::fromCollection($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Thinktomorrow\Vine\Branch\ArrayCollection>, but the function expects a null|object<Thinktomorro...ranch\BranchCollection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
    }
58
}
59