Point   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 49
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 3
A encode() 0 6 1
A toArray() 0 5 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2013-2015 2amigOS! Consulting Group LLC
4
 * @link http://2amigos.us
5
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
6
 */
7
8
namespace dosamigos\leaflet\types;
9
10
use dosamigos\leaflet\LeafLet;
11
use yii\base\InvalidConfigException;
12
use yii\helpers\Json;
13
use yii\web\JsExpression;
14
15
/**
16
 * Point represents a point with x and y coordinates in pixels.
17
 *
18
 * ```
19
 *  $map->panBy(new Point(['x' => 200, 'y' => '300']));
20
 * ```
21
 *
22
 * @see http://leafletjs.com/reference.html#point
23
 * @author Antonio Ramirez <[email protected]>
24
 * @link http://www.ramirezcobos.com/
25
 * @link http://www.2amigos.us/
26
 * @package dosamigos\leaflet\types
27
 */
28
class Point extends Type implements ArrayableInterface
29
{
30
    /**
31
     * @var float x coordinate
32
     */
33
    public $x;
34
    /**
35
     * @var float y coordinate
36
     */
37
    public $y;
38
    /**
39
     * @var bool if round is set to true, LetLeaf will round the x and y values.
40
     */
41
    public $round = false;
42
43
    /**
44
     * Initializes the class
45
     * @throws \yii\base\InvalidConfigException
46
     */
47 12
    public function init()
48
    {
49 12
        if (empty($this->x) || empty($this->y)) {
50 3
            throw new InvalidConfigException("'x' or 'y' cannot be empty.");
51
        }
52 12
    }
53
54
    /**
55
     * @return \yii\web\JsExpression the js initialization code of the object
56
     */
57 3
    public function encode()
58
    {
59 3
        $x = $this->x;
60 3
        $y = $this->y;
61 3
        return new JsExpression("L.point($x, $y)"); // no semicolon
62
    }
63
64
    /**
65
     * Returns the point values as array
66
     *
67
     * @param bool $encode whether to return the array json_encoded or raw
68
     *
69
     * @return array|JsExpression
70
     */
71 12
    public function toArray($encode = false)
72
    {
73 12
        $point = [$this->x, $this->y];
74 12
        return $encode ? new JsExpression(Json::encode($point, LeafLet::JSON_OPTIONS)) : $point;
0 ignored issues
show
Bug Compatibility introduced by
The expression $encode ? new \yii\web\J...SON_OPTIONS)) : $point; of type yii\web\JsExpression|double[] adds the type yii\web\JsExpression to the return on line 74 which is incompatible with the return type declared by the interface dosamigos\leaflet\types\...yableInterface::toArray of type array.
Loading history...
75
    }
76
}
77