Panel::getDefault()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * Pluggable themes for Yii2
4
 *
5
 * @link      https://github.com/hiqdev/yii2-thememanager
6
 * @package   yii2-thememanager
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\thememanager\debug;
12
13
use Yii;
14
use yii\base\ViewContextInterface;
15
use yii\helpers\ArrayHelper;
16
17
class Panel extends \yii\debug\Panel implements ViewContextInterface
18
{
19
    use \hiqdev\thememanager\GetManagerTrait;
20
21
    protected $_viewPath;
22
23
    public function setViewPath($value)
24
    {
25
        $this->_viewPath = $value;
26
    }
27
28
    public function getViewPath()
29
    {
30
        if ($this->_viewPath === null) {
31
            $this->_viewPath = dirname(__DIR__) . '/views/debug';
32
        }
33
34
        return $this->_viewPath;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getName()
41
    {
42
        return 'Themes';
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getSummary()
49
    {
50
        return Yii::$app->view->render('summary', ['panel' => $this], $this);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getDetail()
57
    {
58
        return Yii::$app->view->render('detail', ['panel' => $this], $this);
59
    }
60
61
    public function getThemes()
62
    {
63
        return isset($this->data['themes']) ? $this->data['themes'] : [];
64
    }
65
66
    public function getCount()
67
    {
68
        return count($this->getThemes());
69
    }
70
71
    public function getCurrent()
72
    {
73
        return isset($this->data['current']) ? $this->data['current'] : '';
74
    }
75
76
    public function getDefault()
77
    {
78
        return isset($this->data['default']) ? $this->data['default'] : '';
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function save()
85
    {
86
        $raw = $this->getManager()->getItems();
87
        $themes = ArrayHelper::toArray($raw);
88
        foreach ($raw as $name => $theme) {
89
            $themes[$name]['class'] = get_class($theme);
90
        }
91
92
        return [
93
            'themes' => $themes,
94
            'current' => $this->getManager()->getTheme()->name,
95
            'default' => $this->getManager()->getDefaultTheme(),
96
        ];
97
    }
98
}
99