Passed
Push — master ( ad1515...9a224a )
by Sebastian
01:48
created

ArrayAccessTrait::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (C) 2018 Sebastian Böttger <[email protected]>
4
 * You may use, distribute and modify this code under the
5
 * terms of the MIT license.
6
 *
7
 * You should have received a copy of the MIT license with
8
 * this file. If not, please visit: https://opensource.org/licenses/mit-license.php
9
 */
10
11
namespace Seboettg\Collection\ArrayList;
12
13
use ArrayIterator;
14
15
/**
16
 * Trait ArrayAccessTrait
17
 * @package Seboettg\Collection\ArrayList
18
 * @property $array Base array of this data structure
19
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $array at position 0 could not be parsed: Unknown type name '$array' at position 0 in $array.
Loading history...
20
trait ArrayAccessTrait
21
{
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function getIterator()
26
    {
27
        return new ArrayIterator($this->array);
28
    }
29
30
    /**
31
     * Offset to retrieve
32
     * @link http://php.net/manual/en/arrayaccess.offsetget.php
33
     * @param mixed $offset The offset to retrieve.
34
     *
35
     * @return mixed Can return all value types.
36
     */
37
    public function offsetGet($offset)
38
    {
39
        return isset($this->array[$offset]) ? $this->array[$offset] : null;
40
    }
41
42
    /**
43
     * Offset to set
44
     * @link http://php.net/manual/en/arrayaccess.offsetset.php
45
     * @param mixed $offset The offset to assign the value to.
46
     * @param mixed $value The value to set.
47
     */
48
    public function offsetSet($offset, $value)
49
    {
50
        $this->array[$offset] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property array does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
51
    }
52
53
    /**
54
     * Whether a offset exists
55
     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
56
     *
57
     * @param mixed $offset
58
     * @return bool
59
     */
60
    public function offsetExists($offset)
61
    {
62
        return isset($this->array[$offset]);
63
    }
64
65
    /**
66
     * Offset to unset
67
     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
68
     * @param mixed $offset The offset to unset.
69
     */
70
    public function offsetUnset($offset)
71
    {
72
        unset($this->array[$offset]);
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78
    public function count()
79
    {
80
        return count($this->array);
81
    }
82
}
83