GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AddressCollection   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 87
c 0
b 0
f 0
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIterator() 0 4 1
A count() 0 4 1
A first() 0 8 2
A isEmpty() 0 4 1
A slice() 0 4 1
A has() 0 4 1
A get() 0 8 2
A all() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Model;
14
15
use Geocoder\Collection;
16
use Geocoder\Exception\CollectionIsEmpty;
17
use Geocoder\Exception\OutOfBounds;
18
use Geocoder\Location;
19
20
final class AddressCollection implements Collection
21
{
22
    /**
23
     * @var Location[]
24
     */
25
    private $locations;
26
27
    /**
28
     * @param Location[] $locations
29
     */
30
    public function __construct(array $locations = [])
31
    {
32
        $this->locations = array_values($locations);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function getIterator()
39
    {
40
        return new \ArrayIterator($this->all());
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function count()
47
    {
48
        return count($this->locations);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function first(): Location
55
    {
56
        if (empty($this->locations)) {
57
            throw new CollectionIsEmpty();
58
        }
59
60
        return reset($this->locations);
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function isEmpty(): bool
67
    {
68
        return empty($this->locations);
69
    }
70
71
    /**
72
     * @return Location[]
73
     */
74
    public function slice(int $offset, int $length = null)
75
    {
76
        return array_slice($this->locations, $offset, $length);
77
    }
78
79
    /**
80
     * @return bool
81
     */
82
    public function has(int $index): bool
83
    {
84
        return isset($this->locations[$index]);
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function get(int $index): Location
91
    {
92
        if (!isset($this->locations[$index])) {
93
            throw new OutOfBounds(sprintf('The index "%s" does not exist in this collection.', $index));
94
        }
95
96
        return $this->locations[$index];
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function all(): array
103
    {
104
        return $this->locations;
105
    }
106
}
107