Completed
Push — master ( e52a1e...5c6bea )
by Daniel
02:19
created

LocationCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addLocation() 5 5 1
A pick() 8 8 2
A count() 4 4 1
A getIterator() 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 Jobles\Core\Location;
4
5 View Code Duplication
class LocationCollection implements \IteratorAggregate, \Countable
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...
6
{
7
    /**
8
     * @var array
9
     */
10
    private $locations = [];
11
12
    /**
13
     * @var int
14
     */
15
    private $size = 0;
16
17
    /**
18
     * @param Location $location
19
     */
20 13
    public function addLocation(Location $location)
21
    {
22 13
        $this->locations[] = $location;
23 13
        $this->size++;
24 13
    }
25
26
    /**
27
     * @param $position
28
     * @return LocationInterface
29
     * @throws \LengthException
30
     */
31 4
    public function pick($position)
32
    {
33 4
        if (isset($this->locations[$position])) {
34 3
            return $this->locations[$position];
35
        }
36
37 1
        throw new \LengthException('Invalid location position: ' . $position);
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43 4
    public function count()
44
    {
45 4
        return $this->size;
46
    }
47
48
    /**
49
     * @inheritDoc
50
     */
51 1
    public function getIterator()
52
    {
53 1
        return new LocationIterator($this);
54
    }
55
}
56