GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Slider::rules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace app\models;
4
5
6
use devgroup\TagDependencyHelper\ActiveRecordHelper;
7
use Yii;
8
use yii\helpers\ArrayHelper;
9
10
/**
11
 * This is the model class for table "{{%slider}}".
12
 *
13
 * @property integer $id
14
 * @property string $name
15
 * @property integer $slider_handler_id
16
 * @property integer $image_width
17
 * @property integer $image_height
18
 * @property integer $resize_big_images
19
 * @property integer $resize_small_images
20
 * @property string $css_class
21
 * @property string $params
22
 * @property string $custom_slider_view_file
23
 * @property string $custom_slide_view_file
24
 */
25
class Slider extends \yii\db\ActiveRecord
26
{
27
    private $_slides = null;
28
29
    use \app\traits\FindById;
30
31
    public function behaviors()
32
    {
33
        return [
34
            [
35
                'class' => \devgroup\TagDependencyHelper\ActiveRecordHelper::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
36
            ],
37
        ];
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public static function tableName()
44
    {
45
        return '{{%slider}}';
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function rules()
52
    {
53
        return [
54
            [['slider_handler_id', 'image_width', 'image_height', 'resize_big_images', 'resize_small_images'], 'integer'],
55
            [['params'], 'string'],
56
            [['name', 'css_class', 'custom_slider_view_file', 'custom_slide_view_file'], 'string', 'max' => 255],
57
            [['image_width', 'image_height'], 'default', 'value' => 300],
58
        ];
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64
    public function attributeLabels()
65
    {
66
        return [
67
            'id' => Yii::t('app', 'ID'),
68
            'name' => Yii::t('app', 'Name'),
69
            'slider_handler_id' => Yii::t('app', 'Slider Handler ID'),
70
            'image_width' => Yii::t('app', 'Image Width'),
71
            'image_height' => Yii::t('app', 'Image Height'),
72
            'resize_big_images' => Yii::t('app', 'Resize Big Images'),
73
            'resize_small_images' => Yii::t('app', 'Resize Small Images'),
74
            'css_class' => Yii::t('app', 'Css Class'),
75
            'params' => Yii::t('app', 'Params'),
76
            'custom_slider_view_file' => Yii::t('app', 'Custom Slider View File'),
77
            'custom_slide_view_file' => Yii::t('app', 'Custom Slide View File'),
78
        ];
79
    }
80
81
    /**
82
     * Returns corresponding slides with cache support(not real relation!)
83
     * @return Slide[]
84
     */
85
    public function getSlides($onlyActive = false)
86
    {
87
        if ($this->_slides === null) {
88
            $this->_slides = Yii::$app->cache->get("Slides:" . $this->id);
89
            if (!is_array($this->_slides)) {
90
                $this->_slides = Slide::find()
91
                    ->where(['slider_id' => $this->id])
92
                    ->orderBy('sort_order ASC')
93
                    ->all();
94
                Yii::$app->cache->set(
95
                    "Slides:" . $this->id,
96
                    $this->_slides,
97
                    86400,
98
                    new \yii\caching\TagDependency([
99
                        'tags' => [
100
                            ActiveRecordHelper::getObjectTag(Slider::className(), $this->id)
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
101
                        ]
102
                    ])
103
                );
104
            }
105
        }
106
        if ($onlyActive === true) {
107
            $activeSlides = [];
108
            foreach ($this->_slides as $slide) {
109
                if ($slide->active) {
110
                    $activeSlides[] = $slide;
111
                }
112
            }
113
            return $activeSlides;
114
        } else {
115
            return $this->_slides;
116
        }
117
    }
118
119
    /**
120
     * Returns handler model for this slider
121
     * @return SliderHandler|null
122
     */
123
    public function handler()
124
    {
125
        return SliderHandler::findBySliderId($this->slider_handler_id);
126
    }
127
}
128