Completed
Push — master ( 574828...887cf7 )
by Emily
02:16
created

AbstractList::offsetSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2.032
1
<?php
2
/**
3
 * This file is part of the Composite Utils package.
4
 *
5
 * (c) Emily Shepherd <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the
8
 * LICENSE.md file that was distributed with this source code.
9
 *
10
 * @package spaark/composite-utils
11
 * @author Emily Shepherd <[email protected]>
12
 * @license MIT
13
 */
14
15
namespace Spaark\CompositeUtils\Model\Collection;
16
17
/**
18
 * Represents an abstract collection which acts as a list of items
19
 */
20
abstract class AbstractList
21
    extends AbstractCollection
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "AbstractCollection" and comma; 1 found
Loading history...
22
    implements ListInterface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
23
{
24
    /**
25
     * {@inheritDoc}
26
     */
27 4
    public function offsetSet($offset, $value)
28
    {
29 4
        if ($offset === null)
30
        {
31 4
            $this->push($value);
32
        }
33
        else
34
        {
35
            $this->splice($offset, 0, [$value]);
36
        }
37 4
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function offsetUnset($index)
43
    {
44
        $this->remove($index);
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function offsetExists($index)
51
    {
52
        return $index < $this->size();
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58 1
    public function offsetGet($index)
59
    {
60 1
        return $this->get($index);
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66 1
    public function remove(int $index)
67
    {
68 1
        $this->splice($index, 1);
69 1
    }
70
}
71
72