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
Push — master ( 875358...93eba8 )
by Petr
23:35
created

MapAPI::invalidateMarkers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Application\UI\Control;
12
use Nette\Application\Responses\JsonResponse;
13
14
15
/**
16
 * Description of GoogleAPI
17
 *
18
 * @author Petr Olišar <[email protected]>
19
 */
20
class MapAPI extends Control
21
{
22
23
	const ROADMAP = 'ROADMAP', SATELLITE = 'SATELLITE', HYBRID = 'HYBRID', TERRAIN = 'TERRAIN',
24
		BICYCLING = 'BICYCLING', DRIVING = 'DRIVING', TRANSIT = 'TRANSIT', WALKING = 'WALKING';
25
	
26
	/** @var double|string */
27
	private $width;
28
29
	/** @var double|string */
30
	private $height;
31
32
	/** @var array */
33
	private $coordinates;
34
35
	/** @var Integer */
36
	private $zoom;
37
38
	/** @var String */
39
	private $type;
40
41
	/** @var Boolean */
42
	private $staticMap = FALSE;
43
44
	/** @var Boolean */
45
	private $clickable = FALSE;
46
47
	/** @var String  */
48
	private $key;
49
50
	/** @var array */
51
	private $markers = array();
52
53
	/** @var boolean */
54
	private $bound;
55
56
	/** @var boolean */
57
	private $markerClusterer;
58
59
	/** @var array */
60
	private $clusterOptions;
61
62
	/** @var boolean */
63
	private $scrollable = FALSE;
64
65
	/**
66
	 *
67
	 * @var array
68
	 */
69
	private $waypoints;
70
71
	/**
72
	 *
73
	 * @var array
74
	 */
75
	private $direction = ['travelmode' => 'DRIVING'];
76
77
78
	public function __construct()
79
	{
80
		parent::__construct();
81
	}
82
83
	/**
84
	 * @internal
85
	 * @param array $config
86
	 */
87
	public function setup(array $config)
88
	{
89
		$this->width = $config['width'];
90
		$this->height = $config['height'];
91
	}
92
93
	
94
	/**
95
	 *
96
	 * @param array $coordinates (latitude, longitude) - center of the map
97
	 * @return \Oli\GoogleAPI\MapAPI
98
	 */
99
	public function setCoordinates(array $coordinates)
100
	{
101
		if(!count($coordinates))
102
		{
103
			$this->coordinates = array(NULL, NULL);
104
		} else
105
		{
106
			$this->coordinates = array_values($coordinates);
107
		}
108
		
109
		return $this;
110
	}
111
	
112
	
113
	/**
114
	 * @param double|string $width
115
	 * @param double|string $height
116
	 * @return MapAPI
117
	 */
118
	public function setProportions($width, $height)
119
	{
120
		$this->width = $width;
121
		$this->height = $height;
122
		return $this;
123
	}
124
	
125
	
126
	/**
127
	 *
128
	 * @param string $key
129
	 * @return \Oli\GoogleAPI\MapAPI
130
	 */
131
	public function setKey($key)
132
	{
133
		$this->key = $key;
134
		return $this;
135
	}
136
	
137
	
138
	/**
139
	 *
140
	 * @param int $zoom <0, 19>
141
	 * @return \Oli\GoogleAPI\MapAPI
142
	 * @throws \InvalidArgumentException
143
	 * @throws \LogicException
144
	 */
145
	public function setZoom($zoom)
146
	{
147
		if (!is_int($zoom))
148
		{
149
			throw new \InvalidArgumentException("type must be integer, $zoom (".gettype($zoom).") was given");
150
		}
151
		
152
		if ($zoom < 0 || $zoom > 19)
153
		{
154
			throw new \LogicException('Zoom must be betwen <0, 19>.');
155
		}
156
		
157
		$this->zoom = (int) $zoom;
158
		return $this;
159
	}
160
	
161
	
162
	/**
163
	 *
164
	 * @param String $type
165
	 * @return \Oli\GoogleAPI\MapAPI
166
	 */
167
	public function setType($type)
168
	{
169
		if($type !== self::HYBRID && $type !== self::ROADMAP && $type !== self::SATELLITE &&
170
				$type !== self::TERRAIN)
171
		{
172
			throw new \InvalidArgumentException;
173
		}
174
		$this->type = $type;
175
		return $this;
176
	}
177
	
178
	
179
	public function setWaypoint($key, $waypoint)
180
	{
181
		if($key === 'waypoints')
182
		{
183
			$this->waypoints['waypoints'][] = $waypoint;
184
			
185
		} else
186
		{
187
			$this->waypoints[$key] = $waypoint;
188
		}
189
		return $this;
190
	}
191
	
192
	
193
	public function setDirection(array $direction)
194
	{
195
		$this->direction = $direction;
196
		if(!array_key_exists('travelmode', $this->direction))
197
		{
198
			$this->direction['travelmode'] = 'DRIVING';
199
		}
200
		return $this;
201
	}
202
	
203
	
204
	/**
205
	 * @return array Width and Height of the map.
206
	 */
207
	public function getProportions()
208
	{
209
		return array('width' => $this->width, 'height' => $this->height);
210
	}
211
	
212
	
213
	/**
214
	 * @return array Center of the map
215
	 */
216
	public function getCoordinates()
217
	{
218
		return $this->coordinates;
219
	}
220
	
221
	
222
	/**
223
	 * @return integer Zoom
224
	 */
225
	public function getZoom()
226
	{
227
		return $this->zoom;
228
	}
229
	
230
	
231
	/**
232
	 * @return String Which map type will be show
233
	 */
234
	public function getType()
235
	{
236
		return $this->type;
237
	}
238
239
240
	public function getKey()
241
	{
242
		return $this->key;
243
	}
244
	
245
	
246
	/**
247
	 *
248
	 * @param Boolean $staticMap
249
	 * @return \Oli\GoogleAPI\MapAPI
250
	 * @throws \InvalidArgumentException
251
	 */
252
	public function isStaticMap($staticMap = TRUE)
253
	{
254
		if (!is_bool($staticMap))
255
		{
256
			throw new \InvalidArgumentException("staticMap must be boolean, $staticMap (".gettype($staticMap).") was given");
257
		}
258
		
259
		$this->staticMap = $staticMap;
260
		return $this;
261
	}
262
263
264
	public function getIsStaticMap()
265
	{
266
		return $this->staticMap;
267
	}
268
269
270
	/**
271
	 *
272
	 * @param Boolean $clickable
273
	 * @return \Oli\GoogleAPI\MapAPI
274
	 * @throws \InvalidArgumentException
275
	 */
276
	public function isClickable($clickable = TRUE)
277
	{
278
		if (!$this->staticMap)
279
		{
280
			throw new \InvalidArgumentException("the 'clickable' option only applies to static maps");
281
		}
282
283
		if (!is_bool($clickable))
284
		{
285
			throw new \InvalidArgumentException("clickable must be boolean, $clickable (".gettype($clickable).") was given");
286
		}
287
288
		$this->clickable = $clickable;
289
		return $this;
290
	}
291
292
293
	public function getIsClicable()
294
	{
295
		return $this->clickable;
296
	}
297
298
	
299
	public function isScrollable($scrollable = TRUE)
300
	{
301
		if (!is_bool($scrollable))
302
		{
303
			throw new \InvalidArgumentException("staticMap must be boolean, $scrollable (".gettype($scrollable).") was given");
304
		}
305
		
306
		$this->scrollable = $scrollable;
307
		return $this;
308
	}
309
310
311
	public function getIsScrollable()
312
	{
313
		return $this->scrollable;
314
	}
315
316
317
	/**
318
	 *
319
	 * @param \Oli\GoogleAPI\Markers $markers
320
	 * @return \Oli\GoogleAPI\MapAPI
321
	 */
322
	public function addMarkers(Markers $markers)
323
	{
324
		$this->markers = $markers->getMarkers();
325
		$this->bound = $markers->getBound();
326
		$this->markerClusterer = $markers->getMarkerClusterer();
327
		$this->clusterOptions = $markers->getClusterOptions();
328
		return $this;
329
	}
330
	
331
	
332
	/**
333
	 * Alias to handleMarkers()
334
	 */
335
	public function invalidateMarkers()
336
	{
337
		$this->handleMarkers();
338
	}
339
	
340
	
341
	/**
342
	* @see Nette\Application\Control#render()
343
	*/
344
	public function render()
345
	{
346
		if ($this->staticMap)
347
		{
348
			$this->template->height = $this->height;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing height on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
349
			$this->template->width = $this->width;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing width on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
350
			$this->template->zoom = $this->zoom;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing zoom on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
351
			$this->template->position = $this->coordinates;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing position on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
352
			$this->template->markers = $this->markers;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing markers on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
353
			$this->template->clickable = $this->clickable;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing clickable on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
354
			$this->template->setFile(dirname(__FILE__) . '/static.latte');
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
355
		} else
356
		{
357
			$map = array(
358
			    'position' => $this->coordinates,
359
			    'height' => $this->height,
360
			    'width' => $this->width,
361
			    'zoom' => $this->zoom,
362
			    'type' => $this->type,
363
			    'scrollable' => $this->scrollable,
364
			    'key' => $this->key,
365
			    'bound' => $this->bound,
366
			    'cluster' => $this->markerClusterer,
367
			    'clusterOptions' => $this->clusterOptions,
368
			    'waypoint' => !is_null($this->waypoints) ? array_merge($this->waypoints, $this->direction) : NULL
369
			);
370
			$this->template->map = \Nette\Utils\Json::encode($map);
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing map on the interface Nette\Application\UI\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
371
			$this->template->setFile(dirname(__FILE__) . '/template.latte');
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
372
		}
373
		$this->template->render();
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
374
	}
375
	
376
	
377
	/**
378
	 * Send markers to template as JSON
379
	 * @internal
380
	 */
381
	public function handleMarkers()
382
	{
383
		$this->getPresenter()->sendResponse(new JsonResponse($this->markers));
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Nette\ComponentModel\IComponent as the method sendResponse() does only exist in the following implementations of said interface: Nette\Application\UI\Presenter.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
384
	}
385
}
386