Completed
Push — master ( 77a1b1...6549c6 )
by Brent
86:28 queued 42:27
created

ValueObjectCollection::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Spatie\ValueObject;
4
5
use ArrayAccess;
6
use Countable;
7
use Illuminate\Contracts\Support\Arrayable;
8
use Iterator;
9
10 View Code Duplication
abstract class ValueObjectCollection implements
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
    ArrayAccess,
12
    Iterator,
13
    Countable,
14
    Arrayable
15
{
16
    /** @var array */
17
    protected $collection;
18
19
    /** @var int */
20
    protected $position = 0;
21
22
    public function __construct(array $collection = [])
23
    {
24
        $this->collection = $collection;
25
    }
26
27
    public function current()
28
    {
29
        return $this->collection[$this->position];
30
    }
31
32
    public function offsetGet($offset)
33
    {
34
        return isset($this->collection[$offset]) ? $this->collection[$offset] : null;
35
    }
36
37
    public function offsetSet($offset, $value)
38
    {
39
        if (is_null($offset)) {
40
            $this->collection[] = $value;
41
        } else {
42
            $this->collection[$offset] = $value;
43
        }
44
    }
45
46
    public function offsetExists($offset)
47
    {
48
        return array_key_exists($offset, $this->collection);
49
    }
50
51
    public function offsetUnset($offset)
52
    {
53
        unset($this->collection[$offset]);
54
    }
55
56
    public function next()
57
    {
58
        $this->position++;
59
    }
60
61
    public function key()
62
    {
63
        return $this->position;
64
    }
65
66
    public function valid()
67
    {
68
        return array_key_exists($this->position, $this->collection);
69
    }
70
71
    public function rewind()
72
    {
73
        $this->position = 0;
74
    }
75
76
    public function toArray(): array
77
    {
78
        return $this->collection;
79
    }
80
81
    public function count(): int
82
    {
83
        return count($this->collection);
84
    }
85
}
86