Completed
Push — master ( 887cf7...2ea773 )
by Emily
02:13
created

AbstractList   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 59
ccs 9
cts 18
cp 0.5
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 11 2
A set() 0 4 1
A offsetUnset() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A remove() 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;
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 7
    public function offsetSet($offset, $value)
28
    {
29 7
        if ($offset === null)
30
        {
31 7
            $this->push($value);
32
        }
33
        else
34
        {
35
            $this->set($offset, $value);
36
        }
37 7
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function set(int $index, $value)
43
    {
44
        $this->splice($offset, 0, [$value]);
0 ignored issues
show
Bug introduced by
The variable $offset does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function offsetUnset($index)
51
    {
52
        $this->remove($index);
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    public function offsetExists($index)
59
    {
60
        return $index < $this->size();
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66 3
    public function offsetGet($index)
67
    {
68 3
        return $this->get($index);
69
    }
70
71
    /**
72
     * {@inheritDoc}
73
     */
74 1
    public function remove(int $index)
75
    {
76 1
        $this->splice($index, 1);
77 1
    }
78
}
79
80