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

IndexPageUiOptions::getDefaultOrientation()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 2
nop 0
crap 12
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