Rectangle   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
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 44
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setBounds() 0 5 1
A getBounds() 0 4 1
A encode() 0 12 4
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\layers;
9
10
use dosamigos\leaflet\types\LatLngBounds;
11
use yii\web\JsExpression;
12
13
/**
14
 * Rectangle a class for drawing rectangle overlays on a map.
15
 *
16
 * @see http://leafletjs.com/reference.html#rectangle
17
 * @author Antonio Ramirez <[email protected]>
18
 * @link http://www.ramirezcobos.com/
19
 * @link http://www.2amigos.us/
20
 * @package dosamigos\leaflet\layers
21
 */
22
/**
23
 * @property string $name
24
 * @property string $popupContent
25
 * @property bool $openPopup
26
 */
27
class Rectangle extends Layer
28
{
29
    use PopupTrait;
30
31
    /**
32
     * @var LatLngBounds
33
     */
34
    private $_bounds;
35
36
    /**
37
     * @param LatLngBounds $bounds
38
     */
39 9
    public function setBounds(LatLngBounds $bounds)
40
    {
41 9
        $bounds->name = null;
42 9
        $this->_bounds = $bounds;
43 9
    }
44
45
    /**
46
     * @return LatLngBounds
47
     */
48 9
    public function getBounds()
49
    {
50 9
        return $this->_bounds;
51
    }
52
53
    /**
54
     * Returns the javascript ready code for the object to render
55
     * @return string
56
     */
57 9
    public function encode()
58
    {
59 9
        $bounds = $this->getBounds()->encode();
60 9
        $options = $this->getOptions();
61 9
        $name = $this->name;
62 9
        $map = $this->map;
63 9
        $js = $this->bindPopupContent("L.rectangle($bounds, $options)") . ($map !== null ? ".addTo($map);" : "");
64 9
        if (!empty($name)) {
65 3
            $js = "var $name = $js" . ($map !== null ? "" : ";");
66 3
        }
67 9
        return new JsExpression($js);
68
    }
69
70
}
71