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 (#16)
by
unknown
10:44
created

Markers::getMarkerClusterer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2015 Petr Olišar (http://olisar.eu)
4
 *
5
 * For the full copyright and license information, please view
6
 * the file LICENSE.md that was distributed with this source code.
7
 */
8
9
namespace Oli\GoogleAPI;
10
11
use Nette\Object;
12
use Nette\Utils\Strings;
13
use Oli\GoogleAPI\Marker\Icon;
14
15
16
/**
17
 * Class Markers
18
 * @package Oli\GoogleAPI
19
 * @see https://developers.google.com/maps/documentation/javascript/markers#complex_icons
20
 */
21
class Markers extends Object
22 1
{
23
24
	const DROP = 'DROP', BOUNCE = 'BOUNCE';
25
26
	/**
27
	 * @var array
28
	 */
29
	private $markers = array();
30
31
	/**
32
	 * @var
33
	 */
34
	private $iconDefaultPath;
35
36
	/**
37
	 * @var bool
38
	 */
39
	private $bound = FALSE;
40
41
	/**
42
	 * @var bool
43
	 */
44
	private $markerClusterer = FALSE;
45
46
	/**
47
	 * @var array
48
	 */
49
	private $clusterOptions = array();
50
51
52
	/**
53
	 * @param array $markers
54
	 */
55
	public function addMarkers(array $markers)
56
	{
57
		if(count($markers))
58
		{
59
			foreach($markers as $marker)
60
			{
61
				$this->createMarker($marker);
62
			}
63
		}
64
	}
65
66
67
	/**
68
	 * @param array $position
69
	 * @param bool $animation
70
	 * @param null|string $title
71
	 * @return $this
72
	 */
73
	public function addMarker(array $position, $animation = false, $title = null)
74
	{
75 1
		if (!is_string($animation) && !is_bool($animation))
76 1
		{
77 1
			throw new InvalidArgumentException("Animation must be string or boolean, $animation (" .
78 1
					gettype($animation) . ") was given");
79
		}
80 1 View Code Duplication
		if (!is_string($title) && $title != null)
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...
81 1
		{
82 1
			throw new InvalidArgumentException("Title must be string or null, $title (".gettype($title).") was given");
83
		}
84 1
		$this->markers[] = array(
85 1
			'position' => $position,
86 1
			'title' => $title,
87 1
			'animation' => $animation,
88
			'visible' => true
89 1
		);
90 1
		return $this;
91
	}
92
93
94
	/**
95
	 * @return array
96
	 */
97
	public function getMarker()
98
	{
99 1
		return end($this->markers);
100
	}
101
102
103
	/**
104
	 * @return array
105
	 */
106
	public function getMarkers()
107
	{
108 1
		return $this->markers;
109
	}
110
111
112
	public function deleteMarkers()
113
	{
114 1
		$this->markers = array();
115 1
	}
116
117
118
	/**
119
	 * @param $message
120
	 * @param bool $autoOpen
121
	 * @return $this
122
	 * @throws LogicException
123
	 */
124
	public function setMessage($message, $autoOpen = false)
125
	{
126 1
		if (!count($this->markers))
127 1
		{
128 1
			throw new LogicException("setMessage must be called after addMarker()");
129
		}
130 1
		end($this->markers);         // move the internal pointer to the end of the array
131 1
		$key = key($this->markers);
132 1
		$this->markers[$key]['message'] = $message;
133 1
		$this->markers[$key]['autoOpen'] = $autoOpen;
134 1
		return $this;
135
	}
136
137
	/**
138
	 * @param array $customField
139
	 * @return $this
140
	 * @throws LogicException
141
	 * @throws InvalidArgumentException
142
	 */
143
	public function setCustomField($customField)
144
	{
145
		if (!count($this->markers))
146
		{
147
			throw new LogicException("setCustomField must be called after addMarker()");
148
		}
149
		if (!is_array($customField))
150
		{
151
			throw new InvalidArgumentException("customField must be array, $customField (".gettype($customField).") was given");
152
		}
153
		end($this->markers);         // move the internal pointer to the end of the array
154
		$key = key($this->markers);
155
		$this->markers[$key]['customField'] = $customField;
156
		return $this;
157
	}
158
159
160
	/**
161
	 * @param bool $cluster
162
	 * @return $this
163
	 * @throws InvalidArgumentException
164
	 */
165 View Code Duplication
	public function isMarkerClusterer($cluster = true)
0 ignored issues
show
Duplication introduced by
This method 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...
166
	{
167 1
		if (!is_bool($cluster))
168 1
		{
169 1
			throw new InvalidArgumentException("cluster must be boolean, $cluster (".gettype($cluster).") was given");
170
		}
171
		
172 1
		$this->markerClusterer = $cluster;
173 1
		return $this;
174
	}
175
176
177
	/**
178
	 * @return bool
179
	 */
180
	public function getMarkerClusterer()
181
	{
182 1
		return $this->markerClusterer;
183
	}
184
185
186
	/**
187
	 * @param array $options
188
	 * @return $this
189
	 */
190
	public function setClusterOptions($options = array())
191
	{
192 1
		$this->clusterOptions = $options;
193 1
		return $this;
194
	}
195
196
197
	/**
198
	 * @return array
199
	 */
200
	public function getClusterOptions()
201
	{
202 1
		return $this->clusterOptions;
203
	}
204
205
206
	/**
207
	 * @param bool $bound Show all of markers
208
	 * @return $this
209
	 * @throws InvalidArgumentException
210
	 */
211 View Code Duplication
	public function fitBounds($bound = true)
0 ignored issues
show
Duplication introduced by
This method 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...
212
	{
213 1
		if (!is_bool($bound))
214 1
		{
215 1
			throw new InvalidArgumentException("fitBounds must be boolean, $bound (".gettype($bound).") was given");
216
		}
217
218 1
		$this->bound = $bound;
219 1
		return $this;
220
	}
221
	
222
	
223
	/**
224
	 * @return Boolean
225
	 */
226
	public function getBound()
227
	{
228 1
		return $this->bound;
229
	}
230
231
232
	/**
233
	 * @param string|Icon $icon
234
	 * @return $this
235
	 * @throws LogicException
236
	 */
237
	public function setIcon($icon)
238
	{
239 1
		if (!count($this->markers))
240 1
		{
241 1
			throw new LogicException("setIcon must be called after addMarker()");
242
		}
243 1
		end($this->markers);         // move the internal pointer to the end of the array
244 1
		$key = key($this->markers);
245 1
		if($icon instanceof Marker\Icon)
246 1
		{
247 1
			$icon->setUrl(is_null($this->iconDefaultPath) ? $icon->getUrl() : $this->iconDefaultPath . $icon->getUrl());
248 1
			$this->markers[$key]['icon'] = $icon->getArray();
249
			
250 1
		} else
251
		{
252 1
			$this->markers[$key]['icon'] = is_null($this->iconDefaultPath) ? $icon : $this->iconDefaultPath . $icon;
253
		}
254
255 1
		return $this;
256
	}
257
258
259
	/**
260
	 * @param string $defaultPath
261
	 * @return $this
262
	 */
263
	public function setDefaultIconPath($defaultPath)
264
	{
265 1
		if(!is_null($defaultPath) &&
266 1
			!Strings::endsWith($defaultPath, '/') &&
267 1
			!Strings::endsWith($defaultPath, '\\'))
268 1
		{
269 1
			$defaultPath .= DIRECTORY_SEPARATOR;
270 1
		}
271 1
		$this->iconDefaultPath = $defaultPath;
272 1
		return $this;
273
	}
274
275
276
	/**
277
	 * @return string
278
	 */
279
	public function getDefaultIconPath()
280
	{
281 1
		return $this->iconDefaultPath;
282
	}
283
284
285
	/**
286
	 * @param string $color Color can be 24-bit color or: green, purple, yellow, blue, orange, red
287
	 * @return $this
288
	 */
289
	public function setColor($color)
290
	{
291 1
		$allowed = array('green', 'purple', 'yellow', 'blue', 'orange', 'red');
292 1
		if (!in_array($color, $allowed) && !Strings::match($color, '~^0x[a-f0-9]{6}$~i'))
293 1
		{
294 1
			throw new InvalidArgumentException('Color must be 24-bit color or from the allowed list.');
295
		}
296
297 1
		if (!count($this->markers))
298 1
		{
299 1
			throw new InvalidArgumentException("setColor must be called after addMarker()");
300
		}
301 1
		end($this->markers);         // move the internal pointer to the end of the array
302 1
		$key = key($this->markers);
303 1
		$this->markers[$key]['color'] = $color;
304 1
		return $this;
305
	}
306
307
308
	/**
309
	 * @param array $marker
310
	 */
311
	private function createMarker(array $marker)
312
	{
313
		if(!array_key_exists('coordinates', $marker))
314
		{
315
			throw new InvalidArgumentException('Coordinates must be set in every marker');
316
		}
317
318
		$this->addMarker(array_values($marker['coordinates']),
319
				isset($marker['animation']) ? $marker['animation'] : false,
320
				isset($marker['title']) ? $marker['title'] : null);
321
322
		if(array_key_exists('message', $marker))
323
		{
324
			if(is_array($marker['message']))
325
			{
326
				$message = array_values($marker['message']);
327
				$this->setMessage($message[0], $message[1]);
328
			} else
329
			{
330
				$this->setMessage($marker['message']);
331
			}
332
		}
333
334
		if(array_key_exists('icon', $marker))
335
		{
336
			if(is_array($marker['icon']))
337
			{
338
				$icon = new Marker\Icon($marker['icon']['url']);
339
340
				if(array_key_exists('size', $marker['icon']))
341
				{
342
					$icon->setSize($marker['icon']['size']);
343
				}
344
345
				if(array_key_exists('anchor', $marker['icon']))
346
				{
347
					$icon->setAnchor($marker['icon']['anchor']);
348
				}
349
350
				if(array_key_exists('origin', $marker['icon']))
351
				{
352
					$icon->setOrigin($marker['icon']['origin']);
353
				}
354
				$this->setIcon($icon);
355
356
			} else
357
			{
358
				$this->setIcon($marker['icon']);
359
			}
360
		}
361
362
		if(array_key_exists('color', $marker))
363
		{
364
			$this->setColor($marker['color']);
365
		}
366
	}
367
}
368