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.

Slide::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
use devgroup\TagDependencyHelper\ActiveRecordHelper;
6
use Yii;
7
use yii\data\ActiveDataProvider;
8
9
/**
10
 * This is the model class for table "{{%slide}}".
11
 *
12
 * @property integer $id
13
 * @property integer $slider_id
14
 * @property integer $sort_order
15
 * @property string $image
16
 * @property string $link
17
 * @property string $text
18
 * @property string $custom_view_file
19
 * @property string $css_class
20
 * @property Slider|ActiveRecordHelper $slider
21
 */
22
class Slide extends \yii\db\ActiveRecord
23
{
24
    use \app\traits\FindById;
25
26
    protected function invalidateSliderTags()
27
    {
28
        $slider = $this->slider;
29
        if ($slider !== null) {
30
            $slider->invalidateTags();
0 ignored issues
show
Bug introduced by
The method invalidateTags does only exist in devgroup\TagDependencyHelper\ActiveRecordHelper, but not in app\models\Slider.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
31
        }
32
    }
33
34
    public function behaviors()
35
    {
36
        return [
37
            [
38
                'class' => 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...
39
            ],
40
        ];
41
    }
42
    /**
43
     * @inheritdoc
44
     */
45
    public static function tableName()
46
    {
47
        return '{{%slide}}';
48
    }
49
50
    /**
51
     * @inheritdoc
52
     */
53
    public function rules()
54
    {
55
        return [
56
            [['slider_id', 'sort_order', 'active'], 'integer'],
57
            [['image', 'link', 'custom_view_file', 'css_class'], 'string', 'max' => 255],
58
            [['active'], 'default', 'value'=>1],
59
            [['text'], 'string']
60
        ];
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66 View Code Duplication
    public function attributeLabels()
67
    {
68
        return [
69
            'id' => Yii::t('app', 'ID'),
70
            'slider_id' => Yii::t('app', 'Slider ID'),
71
            'sort_order' => Yii::t('app', 'Sort Order'),
72
            'image' => Yii::t('app', 'Image'),
73
            'link' => Yii::t('app', 'Link'),
74
            'custom_view_file' => Yii::t('app', 'Custom View File'),
75
            'css_class' => Yii::t('app', 'Css Class'),
76
            'active' => Yii::t('app', 'Active'),
77
            'text' => Yii::t('app', 'Text'),
78
        ];
79
    }
80
81
    /**
82
     * Search slides
83
     * @param $params
84
     * @return ActiveDataProvider
85
     */
86 View Code Duplication
    public function search($params)
87
    {
88
        /* @var $query \yii\db\ActiveQuery */
89
        $query = static::find()
90
            ->where(['slider_id' => $this->slider_id])
91
            ->orderBy('sort_order');
92
        $dataProvider = new ActiveDataProvider(
93
            [
94
                'query' => $query,
95
                'pagination' => [
96
                    'pageSize' => 100,
97
                ],
98
            ]
99
        );
100
        if (!($this->load($params))) {
101
            return $dataProvider;
102
        }
103
        return $dataProvider;
104
    }
105
106
    /**
107
     * @return \yii\db\ActiveQuery
108
     */
109
    public function getSlider()
110
    {
111
        return $this->hasOne(Slider::class, ['id' => 'slider_id']);
112
    }
113
114
    /**
115
     * @inheritdoc
116
     */
117
    public function afterSave($insert, $changedAttributes)
118
    {
119
        parent::afterSave($insert, $changedAttributes);
120
        $this->invalidateSliderTags();
121
    }
122
123
    /**
124
     * @inheritdoc
125
     */
126
    public function afterDelete()
127
    {
128
        parent::afterDelete();
129
        $this->invalidateSliderTags();
130
    }
131
}
132