Control   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 7 3
A setName() 0 4 1
A getOptions() 0 4 2
encode() 0 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\controls;
9
10
use dosamigos\leaflet\LeafLet;
11
use yii\base\Component;
12
use yii\helpers\Json;
13
14
/**
15
 * Control is the base class for all Controls
16
 *
17
 * @property string $name
18
 *
19
 * @author Antonio Ramirez <[email protected]>
20
 * @link http://www.ramirezcobos.com/
21
 * @link http://www.2amigos.us/
22
 * @package dosamigos\leaflet\controls
23
 */
24
abstract class Control extends Component
25
{
26
    /**
27
     * @var string the name of the javascript variable that will hold the reference
28
     * to the map object.
29
     */
30
    public $map;
31
    /**
32
     * @var string the initial position of the control (one of the map corners).
33
     */
34
    public $position = 'topright';
35
    /**
36
     * @var array the options for the underlying LeafLetJs JS component.
37
     * Please refer to the LeafLetJs api reference for possible
38
     * [options](http://leafletjs.com/reference.html).
39
     */
40
    public $clientOptions = [];
41
    /**
42
     * @var string the variable name. If not null, then the js creation script
43
     * will be returned as a variable. If null, then the js creation script will
44
     * be returned as a constructor that you can use on other object's configuration options.
45
     */
46
    private $_name;
47
48
    /**
49
     * Returns the name of the layer.
50
     *
51
     * @param boolean $autoGenerate whether to generate a name if it is not set previously
52
     *
53
     * @return string name of the layer.
54
     */
55 24
    public function getName($autoGenerate = false)
56
    {
57 24
        if ($autoGenerate && $this->_name === null) {
58 3
            $this->_name = LeafLet::generateName();
59 3
        }
60 24
        return $this->_name;
61
    }
62
63
    /**
64
     * Sets the name of the layer.
65
     *
66
     * @param string $value name of the layer.
67
     */
68 9
    public function setName($value)
69
    {
70 9
        $this->_name = $value;
71 9
    }
72
73
    /**
74
     * Returns the processed js options
75
     * @return array
76
     */
77 21
    public function getOptions()
78
    {
79 21
        return empty($this->clientOptions) ? '{}' : Json::encode($this->clientOptions, LeafLet::JSON_OPTIONS);
80
    }
81
82
    /**
83
     * Returns the javascript ready code for the object to render
84
     * @return \yii\web\JsExpression
85
     */
86
    abstract public function encode();
87
}
88