Completed
Push — master ( 79f24a...4b5497 )
by Emily
02:16
created

FlexibleList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 52
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A get() 0 4 1
A splice() 0 9 1
A getIterator() 0 4 1
A size() 0 4 1
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\ListCollection;
16
17
use ArrayIterator;
18
19
/**
20
 * Represents an List stored in a PHP array
21
 */
22
class FlexibleList extends AbstractList
23
{
24
    /**
25
     * @var ValueType[]
26
     */
27
    protected $data = [];
28
29
    /**
30
     * {@inheritDoc}
31
     */
32 41
    public function add($item)
33
    {
34 41
        $this->data[] = $item;
35 41
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 11
    public function get(int $index)
41
    {
42 11
        return $this->data[$index];
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 2
    public function splice
49
    (
50
        int $offset,
51
        ?int $length = null,
52
        array $replacement = []
53
    )
54
    {
55 2
        array_splice($this->data, $offset, $length, $replacement);
56 2
    }
57
58
    /**
59
     * {@inheritDoc}
60
     */
61 18
    public function getIterator()
62
    {
63 18
        return new ArrayIterator($this->data);
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     */
69 41
    public function size() : int
70
    {
71 41
        return count($this->data);
72
    }
73
}
74
75