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.

CoordinateCollector::collect()   F
last analyzed

Complexity

Conditions 11
Paths 576

Size

Total Lines 41
Code Lines 21

Duplication

Lines 6
Ratio 14.63 %

Code Coverage

Tests 31
CRAP Score 11

Importance

Changes 0
Metric Value
dl 6
loc 41
ccs 31
cts 31
cp 1
rs 3.2929
c 0
b 0
f 0
cc 11
eloc 21
nc 576
nop 2
crap 11

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Helper\Collector\Base;
13
14
use Ivory\GoogleMap\Base\Coordinate;
15
use Ivory\GoogleMap\Helper\Collector\AbstractCollector;
16
use Ivory\GoogleMap\Helper\Collector\Layer\HeatmapLayerCollector;
17
use Ivory\GoogleMap\Helper\Collector\Overlay\CircleCollector;
18
use Ivory\GoogleMap\Helper\Collector\Overlay\InfoWindowCollector;
19
use Ivory\GoogleMap\Helper\Collector\Overlay\MarkerCollector;
20
use Ivory\GoogleMap\Helper\Collector\Overlay\PolygonCollector;
21
use Ivory\GoogleMap\Helper\Collector\Overlay\PolylineCollector;
22
use Ivory\GoogleMap\Map;
23
24
/**
25
 * @author GeLo <[email protected]>
26
 */
27
class CoordinateCollector extends AbstractCollector
28
{
29
    /**
30
     * @var BoundCollector
31
     */
32
    private $boundCollector;
33
34
    /**
35
     * @var CircleCollector
36
     */
37
    private $circleCollector;
38
39
    /**
40
     * @var InfoWindowCollector
41
     */
42
    private $infoWindowCollector;
43
44
    /**
45
     * @var MarkerCollector
46
     */
47
    private $markerCollector;
48
49
    /**
50
     * @var PolygonCollector
51
     */
52
    private $polygonCollector;
53
54
    /**
55
     * @var PolylineCollector
56
     */
57
    private $polylineCollector;
58
59
    /**
60
     * @var HeatmapLayerCollector
61
     */
62
    private $heatmapLayerCollector;
63
64
    /**
65
     * @param BoundCollector        $boundCollector
66
     * @param CircleCollector       $circleCollector
67
     * @param InfoWindowCollector   $infoWindowCollector
68
     * @param MarkerCollector       $markerCollector
69
     * @param PolygonCollector      $polygonCollector
70
     * @param PolylineCollector     $polylineCollector
71
     * @param HeatmapLayerCollector $heatmapLayerCollector
72
     */
73 284
    public function __construct(
74
        BoundCollector $boundCollector,
75
        CircleCollector $circleCollector,
76
        InfoWindowCollector $infoWindowCollector,
77
        MarkerCollector $markerCollector,
78
        PolygonCollector $polygonCollector,
79
        PolylineCollector $polylineCollector,
80
        HeatmapLayerCollector $heatmapLayerCollector
81
    ) {
82 284
        $this->setBoundCollector($boundCollector);
83 284
        $this->setCircleCollector($circleCollector);
84 284
        $this->setInfoWindowCollector($infoWindowCollector);
85 284
        $this->setMarkerCollector($markerCollector);
86 284
        $this->setPolygonCollector($polygonCollector);
87 284
        $this->setPolylineCollector($polylineCollector);
88 284
        $this->setHeatmapLayerCollector($heatmapLayerCollector);
89 284
    }
90
91
    /**
92
     * @return BoundCollector
93
     */
94 4
    public function getBoundCollector()
95
    {
96 4
        return $this->boundCollector;
97
    }
98
99
    /**
100
     * @param BoundCollector $boundCollector
101
     */
102 284
    public function setBoundCollector(BoundCollector $boundCollector)
103
    {
104 284
        $this->boundCollector = $boundCollector;
105 284
    }
106
107
    /**
108
     * @return CircleCollector
109
     */
110 4
    public function getCircleCollector()
111
    {
112 4
        return $this->circleCollector;
113
    }
114
115
    /**
116
     * @param CircleCollector $circleCollector
117
     */
118 284
    public function setCircleCollector(CircleCollector $circleCollector)
119
    {
120 284
        $this->circleCollector = $circleCollector;
121 284
    }
122
123
    /**
124
     * @return InfoWindowCollector
125
     */
126 4
    public function getInfoWindowCollector()
127
    {
128 4
        return $this->infoWindowCollector;
129
    }
130
131
    /**
132
     * @param InfoWindowCollector $infoWindowCollector
133
     */
134 284
    public function setInfoWindowCollector(InfoWindowCollector $infoWindowCollector)
135
    {
136 284
        $this->infoWindowCollector = $infoWindowCollector;
137 284
    }
138
139
    /**
140
     * @return MarkerCollector
141
     */
142 4
    public function getMarkerCollector()
143
    {
144 4
        return $this->markerCollector;
145
    }
146
147
    /**
148
     * @param MarkerCollector $markerCollector
149
     */
150 284
    public function setMarkerCollector(MarkerCollector $markerCollector)
151
    {
152 284
        $this->markerCollector = $markerCollector;
153 284
    }
154
155
    /**
156
     * @return PolygonCollector
157
     */
158 4
    public function getPolygonCollector()
159
    {
160 4
        return $this->polygonCollector;
161
    }
162
163
    /**
164
     * @param PolygonCollector $polygonCollector
165
     */
166 284
    public function setPolygonCollector(PolygonCollector $polygonCollector)
167
    {
168 284
        $this->polygonCollector = $polygonCollector;
169 284
    }
170
171
    /**
172
     * @return PolylineCollector
173
     */
174 4
    public function getPolylineCollector()
175
    {
176 4
        return $this->polylineCollector;
177
    }
178
179
    /**
180
     * @param PolylineCollector $polylineCollector
181
     */
182 284
    public function setPolylineCollector(PolylineCollector $polylineCollector)
183
    {
184 284
        $this->polylineCollector = $polylineCollector;
185 284
    }
186
187
    /**
188
     * @return HeatmapLayerCollector
189
     */
190 4
    public function getHeatmapLayerCollector()
191
    {
192 4
        return $this->heatmapLayerCollector;
193
    }
194
195
    /**
196
     * @param HeatmapLayerCollector $heatmapLayerCollector
197
     */
198 284
    public function setHeatmapLayerCollector(HeatmapLayerCollector $heatmapLayerCollector)
199
    {
200 284
        $this->heatmapLayerCollector = $heatmapLayerCollector;
201 284
    }
202
203
    /**
204
     * @param Map          $map
205
     * @param Coordinate[] $coordinates
206
     *
207
     * @return Coordinate[]
208
     */
209 252
    public function collect(Map $map, array $coordinates = [])
210
    {
211 252
        if (!$map->isAutoZoom()) {
212 188
            $coordinates = $this->collectValue($map->getCenter(), $coordinates);
213 94
        }
214
215 252 View Code Duplication
        foreach ($this->boundCollector->collect($map) as $bound) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
216 76
            if ($bound->hasCoordinates()) {
217 20
                $coordinates = $this->collectValue($bound->getSouthWest(), $coordinates);
218 48
                $coordinates = $this->collectValue($bound->getNorthEast(), $coordinates);
219 10
            }
220 126
        }
221
222 252
        foreach ($this->circleCollector->collect($map) as $circle) {
223 12
            $coordinates = $this->collectValue($circle->getCenter(), $coordinates);
224 126
        }
225
226 252
        foreach ($this->infoWindowCollector->collect($map) as $infoWindow) {
227 52
            if ($infoWindow->hasPosition()) {
228 44
                $coordinates = $this->collectValue($infoWindow->getPosition(), $coordinates);
0 ignored issues
show
Bug introduced by
It seems like $infoWindow->getPosition() can be null; however, collectValue() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
229 18
            }
230 126
        }
231
232 252
        foreach ($this->markerCollector->collect($map) as $marker) {
233 52
            $coordinates = $this->collectValue($marker->getPosition(), $coordinates);
234 126
        }
235
236 252
        foreach ($this->polygonCollector->collect($map) as $polygon) {
237 12
            $coordinates = $this->collectValues($polygon->getCoordinates(), $coordinates);
238 126
        }
239
240 252
        foreach ($this->polylineCollector->collect($map) as $polyline) {
241 16
            $coordinates = $this->collectValues($polyline->getCoordinates(), $coordinates);
242 126
        }
243
244 252
        foreach ($this->heatmapLayerCollector->collect($map) as $heatmapLayer) {
245 12
            $coordinates = $this->collectValues($heatmapLayer->getCoordinates(), $coordinates);
246 126
        }
247
248 252
        return $coordinates;
249
    }
250
}
251