Bounds::getMax()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 yii\base\InvalidConfigException;
11
use yii\web\JsExpression;
12
13
14
/**
15
 * Bounds represents a rectangular area in pixel coordinates.
16
 *
17
 * @see http://leafletjs.com/reference.html#bounds
18
 * @author Antonio Ramirez <[email protected]>
19
 * @link http://www.ramirezcobos.com/
20
 * @link http://www.2amigos.us/
21
 * @package dosamigos\leaflet\types
22
 */
23
24
/**
25
 * @property Point $min
26
 * @property Point $max
27
 */
28
class Bounds extends Type implements ArrayableInterface
29
{
30
31
    /**
32
     * @var Point the top left corner of the rectangle
33
     */
34
    private $_min;
35
36
    /**
37
     * @var Point the bottom right corner of the rectangle
38
     */
39
    private $_max;
40
41
    /**
42
     * @param Point $max
43
     */
44 3
    public function setMax(Point $max)
45
    {
46 3
        $this->_max = $max;
47 3
    }
48
49
    /**
50
     * @return Point
51
     */
52 3
    public function getMax()
53
    {
54 3
        return $this->_max;
55
    }
56
57
    /**
58
     * @param Point $min
59
     */
60 3
    public function setMin(Point $min)
61
    {
62 3
        $this->_min = $min;
63 3
    }
64
65
    /**
66
     * @return Point
67
     */
68 3
    public function getMin()
69
    {
70 3
        return $this->_min;
71
    }
72
73
    /**
74
     * Initializes the object
75
     * @throws \yii\base\InvalidConfigException
76
     */
77 3
    public function init()
78
    {
79 3
        if (empty($this->min) || empty($this->max)) {
80 3
            throw new InvalidConfigException("'min' and 'max' attributes cannot be empty.");
81
        }
82 3
    }
83
84
    /**
85
     * @return \yii\web\JsExpression the js initialization code of the object
86
     */
87 3
    public function encode()
88
    {
89 3
        $min = $this->getMin()->toArray(true);
90 3
        $max = $this->getMax()->toArray(true);
91
92 3
        return new JsExpression("L.bounds($min, $max)");
93
    }
94
95
    /**
96
     * Converts the object into an array.
97
     *
98
     * @param bool $encode whether to return the array json_encoded or raw
99
     *
100
     * @return array the array representation of this object
101
     */
102 3
    public function toArray($encode = false)
103
    {
104 3
        $min = $this->getMin()->toArray($encode);
105 3
        $max = $this->getMax()->toArray($encode);
106 3
        return $encode ? "[$min, $max]" : [$min, $max];
107
    }
108
109
110
}
111