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.
Completed
Pull Request — master (#177)
by Eric
08:46 queued 06:24
created

PlaceSearchResponseIterator   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A current() 0 6 2
A next() 0 21 4
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Ivory Google Map package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ivory\GoogleMap\Service\Place\Search\Response;
13
14
use Ivory\GoogleMap\Service\Place\Search\PlaceSearchService;
15
use Ivory\GoogleMap\Service\Place\Search\Request\PageTokenPlaceSearchRequest;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class PlaceSearchResponseIterator implements \Iterator
21
{
22
    /**
23
     * @var PlaceSearchService
24
     */
25
    private $service;
26
27
    /**
28
     * @var PlaceSearchResponse[]
29
     */
30
    private $responses = [];
31
32
    /**
33
     * @var int|null
34
     */
35
    private $position = 0;
36
37
    /**
38
     * @param PlaceSearchService  $service
39
     * @param PlaceSearchResponse $response
40
     */
41
    public function __construct(PlaceSearchService $service, PlaceSearchResponse $response)
42
    {
43
        $this->service = $service;
44
        $this->responses[] = $response;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function current()
51
    {
52
        if ($this->valid()) {
53
            return $this->responses[$this->position];
54
        }
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function next()
61
    {
62
        if (!$this->valid()) {
63
            return;
64
        }
65
66
        ++$this->position;
67
68
        if ($this->valid()) {
69
            return;
70
        }
71
72
        $response = end($this->responses);
73
74
        if (!$response->hasNextPageToken()) {
75
            return;
76
        }
77
78
        $request = new PageTokenPlaceSearchRequest($response);
79
        $this->responses[] = $this->service->process($request)->current();
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function key()
86
    {
87
        return $this->position;
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function valid()
94
    {
95
        return $this->position < count($this->responses);
96
    }
97
98
    /**
99
     * {@inheritdoc}
100
     */
101
    public function rewind()
102
    {
103
        $this->position = 0;
104
    }
105
}
106