Completed
Push — master ( bed82d...5b1b17 )
by Dmitry
02:54
created

Settings::save()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 5
cp 0
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Theme Manager for Yii2
5
 *
6
 * @link      https://github.com/hiqdev/yii2-thememanager
7
 * @package   yii2-thememanager
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\thememanager\models;
13
14
class Settings extends \yii\base\Model
15
{
16
    /**
17
     * @var string theme name
18
     */
19
    public $theme;
20
21
    public function rules()
22
    {
23
        return [
24
            [['theme'], 'safe'],
25
        ];
26
    }
27
28
    /**
29
     * @var array default values for attributes
30
     */
31
    protected $_defaults = [];
32
33
    public function load($data = null)
34
    {
35
        if (!$data) {
36
            return false;
37
        }
38
        parent::load($data, '');
39
        foreach ($this->_defaults as $k => $v) {
40
            if (is_null($this->$k)) {
41
                $this->$k = $v;
42
            }
43
        }
44
45
        return true;
46
    }
47
48
    /**
49
     * Default css provider - returns plain value, fits for attributes like skin and layout.
50
     * @param $name  string         attribute name
51
     * @param $value boolean|string attribute value
52
     * @return string css class
53
     */
54
    public static function cssClassProvider($name, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        return $value;
57
    }
58
59
    public function getCssClass($name)
60
    {
61
        return static::cssClassProvider($name, $this->$name);
62
    }
63
64
    public function getCssClasses(array $names)
65
    {
66
        $classes = [];
67
68
        foreach ($names as $n) {
69
            $classes[$n] = $this->getCssClass($n);
70
        }
71
72
        return implode(' ', array_filter($classes));
73
    }
74
}
75