Passed
Pull Request — master (#5)
by
unknown
02:51 queued 12s
created

ArrayAccessTrait::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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