Panel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 5 1
A afterValidate() 0 7 2
A getOptions() 0 8 2
A render() 0 5 1
1
<?php
2
3
namespace cornernote\dashboard;
4
5
use cornernote\dashboard\models\DashboardPanel;
6
use Yii;
7
use yii\base\Model;
8
use yii\bootstrap\ActiveForm;
9
10
/**
11
 * Panel
12
 * @package cornernote\dashboard
13
 */
14
class Panel extends Model
15
{
16
    /**
17
     * @var string
18
     */
19
    public $id;
20
21
    /**
22
     * @var string
23
     */
24
    public $viewPath;
25
26
    /**
27
     * @var DashboardPanel
28
     */
29
    public $dashboardPanel;
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function load($data, $formName = null)
35
    {
36
        $this->dashboardPanel->load($data);
37
        return parent::load($data, $formName);
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function afterValidate()
44
    {
45
        if (!$this->dashboardPanel->validate()) {
46
            $this->addError(null);
47
        }
48
        parent::afterValidate();
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    public function getOptions()
55
    {
56
        $attributes = [];
57
        foreach($this->safeAttributes() as $attribute){
58
            $attributes[$attribute] = $this->$attribute;
59
        }
60
        return $attributes;
61
    }
62
63
    /**
64
     * @param string $view
65
     * @param array $params
66
     * @return string
67
     */
68
    public function render($view, $params = [])
69
    {
70
        $params['panel'] = $this;
71
        return \Yii::$app->view->render($this->viewPath . '/' . $view, $params);
72
    }
73
74
}
75