Completed
Push — master ( 4d2fcc...d1e17e )
by Klochok
03:39
created

IndexPageUiOptions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 58
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A fields() 0 4 1
A rules() 0 14 1
A getOrientationOptions() 0 7 1
A getDefaultOrientation() 0 11 3
1
<?php
2
3
namespace hipanel\models;
4
5
use Yii;
6
use yii\base\Model;
7
8
class IndexPageUiOptions extends Model
9
{
10
    public $sort;
11
12
    public $per_page;
13
14
    public $orientation;
15
16
    public $representation;
17
18
    public $representationOptions = [];
19
20
    public function fields()
21
    {
22
        return ['sort', 'per_page', 'orientation', 'representation'];
23
    }
24
25
    public function rules()
26
    {
27
        return [
28
            ['per_page', 'default', 'value' => 25],
29
            ['per_page', 'number', 'skipOnEmpty' => true],
30
31
            ['sort', 'string', 'skipOnEmpty' => true],
32
33
            ['orientation', 'default', 'value' => $this->getDefaultOrientation()],
34
            ['orientation', 'in', 'range' => array_keys($this->getOrientationOptions())],
35
36
            ['representation', 'in', 'range' => $this->representationOptions, 'skipOnEmpty' => true],
37
        ];
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function getOrientationOptions()
44
    {
45
        return [
46
            'horizontal' => Yii::t('hipanel', 'Horizontal'),
47
            'vertical' => Yii::t('hipanel', 'Vertical'),
48
        ];
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    public function getDefaultOrientation()
55
    {
56
        $settings = Yii::$app->themeManager->getSettings();
57
        $orientationOptions = array_keys($this->getOrientationOptions());
58
59
        if (property_exists($settings, 'filterOrientation') && in_array($settings->filterOrientation, $orientationOptions, true)) {
60
            return $settings->filterOrientation;
61
        } else {
62
            return reset($orientationOptions);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression reset($orientationOptions); of type string|false adds false to the return on line 62 which is incompatible with the return type documented by hipanel\models\IndexPage...::getDefaultOrientation of type string. It seems like you forgot to handle an error condition.
Loading history...
63
        }
64
    }
65
}
66