Popup   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 5
dl 0
loc 40
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 7 2
A encode() 0 13 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 yii\base\InvalidConfigException;
11
use yii\web\JsExpression;
12
13
/**
14
 * Popup is used to open popups in certain places of the map. For popups directly attached to an
15
 * object (ie [[Marker]]) better use their `popup` attribute.
16
 *
17
 * @see http://leafletjs.com/reference.html#popup
18
 * @package dosamigos\leaflet\layers
19
 */
20
21
/**
22
 * @property \dosamigos\leaflet\types\LatLng $latLng
23
 */
24
class Popup extends Layer
25
{
26
27
    use LatLngTrait;
28
29
    /**
30
     * @var string the HTML content of the popup
31
     */
32
    public $content;
33
34
    /**
35
     * Initializes the marker.
36
     * @throws \yii\base\InvalidConfigException
37
     */
38 9
    public function init()
39
    {
40 9
        parent::init();
41 9
        if (empty($this->latLng)) {
42 3
            throw new InvalidConfigException("'latLon' attribute cannot be empty.");
43
        }
44 6
    }
45
46
    /**
47
     * Returns the javascript ready code for the object to render
48
     * @return string
49
     */
50 3
    public function encode()
51
    {
52 3
        $latLon = $this->getLatLng()->encode();
53 3
        $options = $this->getOptions();
54 3
        $name = $this->name;
55 3
        $map = $this->map;
56 3
        $js = "L.popup($options).setLatLng($latLon).setContent('$this->content')" . ($map !== null ? ".addTo($map);" : "");
57 3
        if (!empty($name)) {
58 3
            $js = "var $name = $js" . ($map !== null ? "" : ";");
59 3
        }
60
61 3
        return new JsExpression($js);
62
    }
63
}
64