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

LocationCollection::addLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 5
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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