Completed
Push — master ( 2df537...506e39 )
by Klochok
13:14
created

Settings::orientationOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 2
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * AdminLte Theme for hiqdev/yii2-thememanager
4
 *
5
 * @link      https://github.com/hiqdev/yii2-theme-adminlte
6
 * @package   yii2-theme-adminlte
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\themes\adminlte\models;
12
13
use Yii;
14
15
class Settings extends \hiqdev\thememanager\models\Settings
16
{
17
    protected $_defaults = [
18
        'skin' => 'skin-blue',
19
    ];
20
21
    /**
22
     * Can have values: fixed, layout-boxed.
23
     *
24
     * @var string
25
     */
26
    public $layout;
27
28
    /**
29
     * Can have values: skin-blue, skin-yellow, skin-purple, skin-green, skin-red, skin-black, skin-ebony.
30
     *
31
     * @var string
32
     */
33
    public $skin;
34
35
    /**
36
     * Can have value: table-condensed, blank.
37
     *
38
     * @var bool
39
     */
40
    public $table_condensed;
41
42
    /**
43
     * @var bool
44
     */
45
    public $collapsed_sidebar;
46
47
    /**
48
     * @var string
49
     */
50
    public $filterOrientation;
51
52
    /**
53
     * @return array
54
     */
55
    public function rules()
56
    {
57
        return [
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array(array(array...ENTATION_HORIZONTAL))); (array<*,string|string[]>[]) is incompatible with the return type of the parent method hiqdev\thememanager\models\Settings::rules of type array<string[]|string>[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
58
            [['layout', 'skin', 'table_condensed', 'collapsed_sidebar'], 'safe'],
59
            [['filterOrientation'], 'in', 'range' => [self::ORIENTATION_VERTICAL, self::ORIENTATION_HORIZONTAL]],
60
        ];
61
    }
62
63
    /**
64
     * @return array
65
     */
66
    public function orientationOptions()
67
    {
68
        return [
69
            self::ORIENTATION_HORIZONTAL => Yii::t('adminlte', 'Horizontal'),
70
            self::ORIENTATION_VERTICAL   => Yii::t('adminlte', 'Vertical'),
71
        ];
72
    }
73
74
    /**
75
     * @return array
76
     */
77
    public function formLayoutData()
78
    {
79
        return [
80
            'none'         => Yii::t('adminlte', 'Default layout'),
81
            'fixed'        => Yii::t('adminlte', 'Fixed layout'),
82
            // working incorectly temporary disabled
83
            // 'layout-boxed' => Yii::t('adminlte', 'Boxed layout'),
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
84
        ];
85
    }
86
87
    /**
88
     * @return array
89
     */
90
    public function attributeLabels()
91
    {
92
        return [
93
            'verifyCode'        => 'Verification Code',
94
            'table_condensed'   => Yii::t('adminlte', 'Table Condensed'),
95
            'collapsed_sidebar' => Yii::t('adminlte', 'Collapsed Sidebar'),
96
            'filterOrientation' => Yii::t('adminlte', 'Search position'),
97
        ];
98
    }
99
100
    /**
101
     * @return array
102
     */
103
    public function skinSampleArray()
104
    {
105
        return [
106
            [
107
                'attribute' => 'skin-red',
108
                'label'     => Yii::t('adminlte', 'Red'),
109
                'color'     => '#dd4b39',
110
                'bg'        => 'bg-red',
111
            ],
112
            [
113
                'attribute' => 'skin-green',
114
                'label'     => Yii::t('adminlte', 'Green'),
115
                'color'     => '#00a65a',
116
                'bg'        => 'bg-green',
117
            ],
118
            [
119
                'attribute' => 'skin-blue',
120
                'label'     => Yii::t('adminlte', 'Blue'),
121
                'color'     => '#3c8dbc',
122
                'bg'        => 'bg-light-blue',
123
            ],
124
            [
125
                'attribute' => 'skin-purple',
126
                'label'     => Yii::t('adminlte', 'Purple'),
127
                'color'     => '#605ca8',
128
                'bg'        => 'bg-purple',
129
            ],
130
            [
131
                'attribute' => 'skin-yellow',
132
                'label'     => Yii::t('adminlte', 'Yellow'),
133
                'color'     => '#f39c12',
134
                'bg'        => 'bg-yellow',
135
            ],
136
            /*[
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
137
                'attribute' => 'skin-black',
138
                'label'     => Yii::t('adminlte', 'Black'),
139
                'color'     => '#fff',
140
                'bg'        => 'bg-black',
141
            ],
142
            [
143
                'attribute' => 'skin-ebony',
144
                'label'     => Yii::t('adminlte', 'Ebony'),
145
                'color'     => '#fff',
146
                'bg'        => 'bg-black',
147
            ],*/
148
        ];
149
    }
150
151
    /**
152
     * Provides css class by given attribute name and value.
153
     *
154
     * @param $name  string         attribute name
155
     * @param $value boolean|string attribute value
156
     *
157
     * @return string css class
158
     */
159
    public static function cssClassProvider($name, $value)
160
    {
161
        switch ($name) {
162
            case 'table_condensed':
163
                return $value ? 'table-condensed' : '';
164
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
165
            case 'collapsed_sidebar':
166
                return $value ? 'sidebar-collapse' : '';
167
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
168
            default:
169
                return parent::cssClassProvider($name, $value);
170
        }
171
    }
172
173
    public function getBodyClasses()
174
    {
175
        return $this->getCssClasses(['layout', 'skin', 'table_condensed', 'collapsed_sidebar']);
176
    }
177
}
178