Base   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
eloc 17
c 1
b 0
f 1
dl 0
loc 54
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getClientOptions() 0 7 1
A init() 0 8 3
A run() 0 3 1
A registerAsset() 0 4 1
1
<?php
2
3
namespace backend\widgets\chart\morris;
4
5
use backend\widgets\chart\morris\assets\MorrisAsset;
6
use yii\base\Widget;
7
use yii\helpers\ArrayHelper;
8
use yii\helpers\Html;
9
10
/**
11
 * Class Base
12
 *
13
 * @package backend\widgets\chart\morris
14
 */
15
abstract class Base extends Widget
16
{
17
    /** @var bool */
18
    public $status = true;
19
    /** @var array */
20
    public $containerOptions = [];
21
    /** @var array */
22
    public $clientOptions = [];
23
24
    /**
25
     * @inheritDoc
26
     */
27
    public function init()
28
    {
29
        parent::init();
30
        if ($this->status === true) {
31
            $this->registerAsset();
32
        }
33
        $this->id = $this->id ?: $this->getId();
34
        ArrayHelper::setValue($this->containerOptions, 'id', $this->id);
35
    }
36
37
    /**
38
     * Run
39
     *
40
     * @return string
41
     */
42
    public function run()
43
    {
44
        return Html::tag('div', '', $this->containerOptions);
45
    }
46
47
    /**
48
     * Client Options
49
     *
50
     * @return array
51
     */
52
    public function getClientOptions()
53
    {
54
        return [
55
            'element' => $this->id,
56
            'resize' => true,
57
            'hideHover' => 'auto',
58
            'data' => [],
59
        ];
60
    }
61
62
    /**
63
     * Register Asset
64
     */
65
    public function registerAsset()
66
    {
67
        $view = $this->getView();
68
        MorrisAsset::register($view);
69
    }
70
}
71