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

ValueObjectCollection   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 76
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 76
loc 76
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A current() 4 4 1
A offsetGet() 4 4 2
A offsetSet() 8 8 2
A offsetExists() 4 4 1
A offsetUnset() 4 4 1
A next() 4 4 1
A key() 4 4 1
A valid() 4 4 1
A rewind() 4 4 1
A toArray() 4 4 1
A count() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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