Passed
Push — master ( 04557a...1df131 )
by Alexey
03:13
created

MapAsset::getMapsArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace backend\widgets\map\jvector\assets;
4
5
use yii\base\InvalidArgumentException;
6
use yii\web\AssetBundle;
7
8
/**
9
 * Class Map
10
 *
11
 * @package backend\widgets\map\jvector\assets
12
 *
13
 * @property-read string[] $mapsArray
14
 */
15
class MapAsset extends AssetBundle
16
{
17
    /** @var string */
18
    public static $mapName = 'world_mill_en';
19
    /** @var string */
20
    public $sourcePath = __DIR__ . '/src/maps';
21
    /** @var string|null */
22
    private $map;
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function init()
28
    {
29
        parent::init();
30
        $maps = $this->getMapsArray();
31
        if (!empty($maps[self::$mapName])) {
32
            $this->setMap($maps[self::$mapName]);
33
            $this->js = [
34
                'jquery-jvectormap-' . $this->getMap() . '.js'
35
            ];
36
        } else {
37
            throw new InvalidArgumentException(__class__ . ': Incorrect map name: "' . self::$mapName . '"');
38
        }
39
    }
40
41
    /**
42
     * @return string[]
43
     */
44
    public function getMapsArray()
45
    {
46
        return [
47
            'world_mill_en' => 'world-mill-en'
48
        ];
49
    }
50
51
    /**
52
     * @param string $value
53
     */
54
    public function setMap($value = '')
55
    {
56
        $this->map = $value;
57
    }
58
59
    /**
60
     * @return string|null
61
     */
62
    public function getMap()
63
    {
64
        return $this->map;
65
    }
66
67
    /**
68
     * @var string[]
69
     */
70
    public $depends = [
71
        JVectorMapAsset::class,
72
    ];
73
}
74