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.
Passed
Push — master ( c721cc...3ff35f )
by Ivan
09:59
created

BackendWarehouseController::actionDeleteEmail()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 1
1
<?php
2
3
namespace app\modules\shop\controllers;
4
5
use app\backend\components\BackendController;
6
use app\components\SearchModel;
7
use app\modules\shop\models\Product;
8
use app\modules\shop\models\WarehouseEmail;
9
use app\modules\shop\models\WarehouseOpeninghours;
10
use app\modules\shop\models\WarehousePhone;
11
use devgroup\TagDependencyHelper\ActiveRecordHelper;
12
use app\backend\actions\DeleteOne;
13
use app\backend\actions\MultipleDelete;
14
use app\backend\actions\UpdateEditable;
15
use app\modules\shop\models\Warehouse;
16
use app\modules\shop\models\WarehouseProduct;
17
use yii\helpers\Url;
18
use Yii;
19
use yii\data\ActiveDataProvider;
20
use yii\filters\AccessControl;
21
use yii\web\HttpException;
22
use yii\web\NotFoundHttpException;
23
use yii\caching\TagDependency;
24
25
class BackendWarehouseController extends BackendController
26
{
27
    /**
28
     * @inheritdoc
29
     */
30 View Code Duplication
    public function behaviors()
31
    {
32
        return [
33
            'access' => [
34
                'class' => AccessControl::className(),
35
                'rules' => [
36
                    [
37
                        'allow' => true,
38
                        'roles' => ['product manage'],
39
                    ],
40
                ],
41
            ],
42
        ];
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function actions()
49
    {
50
        return [
51
            'remove-all' => [
52
                'class' => MultipleDelete::className(),
53
                'modelName' => Warehouse::className(),
54
            ],
55
            'delete' => [
56
                'class' => DeleteOne::className(),
57
                'modelName' => Warehouse::className(),
58
            ],
59
            'update-editable' => [
60
                'class' => UpdateEditable::className(),
61
                'modelName' => Warehouse::className(),
62
                'allowedAttributes' => [
63
                ],
64
            ],
65
        ];
66
    }
67
68
    public function actionIndex()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
69
    {
70
        ;
71
        $searchModel = new SearchModel(
72
            [
73
                'model' => Warehouse::className(),
74
                'partialMatchAttributes' => ['name'],
75
                'scenario' => 'default',
76
            ]
77
        );
78
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
79
        return $this->render(
80
            'index',
81
            [
82
                'dataProvider' => $dataProvider,
83
                'searchModel' => $searchModel,
84
            ]
85
        );
86
    }
87
88
    public function actionEdit($id = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
89
    {
90
        $model = new Warehouse;
91
        $model->loadDefaultValues();
92
93
        if ($id !== null) {
94
            $model = Warehouse::findOne($id);
95
        }
96
97
98 View Code Duplication
        if ($model->load(Yii::$app->request->post()) && $model->validate()) {
99
            if ($model->save()) {
100
                Yii::$app->session->setFlash('info', Yii::t('app', 'Object saved'));
101
                $returnUrl = Yii::$app->request->get(
102
                    'returnUrl',
103
                    ['/shop/backend-warehouse/index']
104
                );
105
                switch (Yii::$app->request->post('action', 'save')) {
106
                    case 'next':
107
                        return $this->redirect(
108
                            [
109
                                '/shop/backend-warehouse/edit',
110
                                'returnUrl' => $returnUrl,
111
                            ]
112
                        );
113
                    case 'back':
114
                        return $this->redirect($returnUrl);
115
                    default:
116
                        return $this->redirect(
117
                            Url::toRoute(
118
                                [
119
                                    '/shop/backend-warehouse/edit',
120
                                    'id' => $model->id,
121
                                    'returnUrl' => $returnUrl,
122
                                ]
123
                            )
124
                        );
125
                }
126
            }
127
128
129
        }
130
131
        $wareHouseOpeningHours = WarehouseOpeninghours::find()->where(['warehouse_id' => $model->id])->one();
132
        if ($wareHouseOpeningHours === null) {
133
            $wareHouseOpeningHours = new WarehouseOpeninghours();
134
        }
135
        $wareHouseOpeningHours->loadDefaultValues();
136 View Code Duplication
        if (Yii::$app->request->post('WarehouseOpeninghours') && !$model->isNewRecord) {
137
            $wareHouseOpeningHours->load(Yii::$app->request->post());
138
            $wareHouseOpeningHours->warehouse_id = $model->id;
139
            if ($wareHouseOpeningHours->save()) {
140
                $this->refresh();
141
            }
142
        }
143
144
        $warehousePhone = new WarehousePhone();
145
146 View Code Duplication
        if (Yii::$app->request->post('WarehousePhone') && !$model->isNewRecord) {
147
            $warehousePhone->loadDefaultValues();
148
            $warehousePhone->load(Yii::$app->request->post());
149
            $warehousePhone->warehouse_id = $model->id;
150
            if ($warehousePhone->save()) {
151
                $this->refresh();
152
            }
153
154
        }
155
        $warehousePhoneProvider = new ActiveDataProvider([
156
            'query' => $warehousePhone::find()->where(['warehouse_id' => $model->id]),
157
            'pagination' => [
158
                'pageSize' => 20,
159
            ],
160
        ]);
161
162
163
        $warehouseEmail = new WarehouseEmail();
164 View Code Duplication
        if (Yii::$app->request->post('WarehouseEmail') && !$model->isNewRecord) {
165
            $warehouseEmail->loadDefaultValues();
166
            $warehouseEmail->load(Yii::$app->request->post());
167
            $warehouseEmail->warehouse_id = $model->id;
168
            if ($warehouseEmail->save()) {
169
                $this->refresh();
170
            }
171
172
        }
173
        $warehouseEmailProvider = new ActiveDataProvider([
174
            'query' => $warehouseEmail::find()->where(['warehouse_id' => $model->id]),
175
            'pagination' => [
176
                'pageSize' => 20,
177
            ],
178
        ]);
179
180
181
        return $this->render(
182
            'form',
183
            [
184
                'model' => $model,
185
                'wareHouseOpeningHours' => $wareHouseOpeningHours,
186
                'warehousePhone' => $warehousePhone,
187
                'warehousePhoneProvider' => $warehousePhoneProvider,
188
                'warehouseEmail' => $warehouseEmail,
189
                'warehouseEmailProvider' => $warehouseEmailProvider
190
            ]
191
        );
192
    }
193
194
195 View Code Duplication
    public function actionDelete($id)
196
    {
197
        if (!$model = Warehouse::findOne($id)) {
198
            throw new NotFoundHttpException;
199
        }
200
201
        if (!$model->delete()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $model->delete() of type false|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
202
            Yii::$app->session->setFlash('info', Yii::t('app', 'Object not removed'));
203
        } else {
204
            Yii::$app->session->setFlash('info', Yii::t('app', 'Object removed'));
205
        }
206
207
        return $this->redirect(
208
            Yii::$app->request->get(
209
                'returnUrl',
210
                '/shop/backend-warehouse/index'
211
            )
212
        );
213
    }
214
215 View Code Duplication
    public function actionEditPhone($id, $returnUrl)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
216
    {
217
        $warehousePhone = WarehousePhone::findOne($id);
218
219
        if (Yii::$app->request->post('WarehousePhone')) {
220
            $warehousePhone->loadDefaultValues();
221
            $warehousePhone->load(Yii::$app->request->post());
222
            if ($warehousePhone->save()) {
223
                $this->redirect($returnUrl);
224
            }
225
        }
226
227
228
229
        return $this->render('form_edit_phone', ['warehousePhone' => $warehousePhone]);
230
    }
231
232
233 View Code Duplication
    public function actionEditEmail($id, $returnUrl)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
234
    {
235
        $warehouseEmail = WarehouseEmail::findOne($id);
236
237
        if (Yii::$app->request->post('WarehouseEmail')) {
238
            $warehouseEmail->loadDefaultValues();
239
            $warehouseEmail->load(Yii::$app->request->post());
240
            if ($warehouseEmail->save()) {
241
                $this->redirect($returnUrl);
242
            }
243
        }
244
245
        return $this->render('form_edit_email', ['warehouseEmail' => $warehouseEmail]);
246
    }
247
248 View Code Duplication
    public function actionDeletePhone($id)
249
    {
250
        if (!$model = WarehousePhone::findOne($id)) {
251
            throw new NotFoundHttpException;
252
        }
253
254
        if (!$model->delete()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $model->delete() of type false|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
255
            Yii::$app->session->setFlash('info', Yii::t('app', 'Object not removed'));
256
        } else {
257
            Yii::$app->session->setFlash('info', Yii::t('app', 'Object removed'));
258
        }
259
260
        return $this->redirect(
261
            Yii::$app->request->get(
262
                'returnUrl',
263
                '/shop/backend-warehouse/index'
264
            )
265
        );
266
    }
267
268 View Code Duplication
    public function actionDeleteEmail($id)
269
    {
270
        if (!$model = WarehouseEmail::findOne($id)) {
271
            throw new NotFoundHttpException;
272
        }
273
274
        if (!$model->delete()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $model->delete() of type false|integer is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
275
            Yii::$app->session->setFlash('info', Yii::t('app', 'Object not removed'));
276
        } else {
277
            Yii::$app->session->setFlash('info', Yii::t('app', 'Object removed'));
278
        }
279
280
        return $this->redirect(
281
            Yii::$app->request->get(
282
                'returnUrl',
283
                '/shop/backend-warehouse/index'
284
            )
285
        );
286
    }
287
288
289
    public function actionUpdateRemains()
290
    {
291
        $post = Yii::$app->request->post('remain', null);
292
        if (isset($post)) {
293
            Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
294
            $remainId = current(array_keys($post));
295
            /** @var WarehouseProduct $model */
296
            $model = WarehouseProduct::findOne($remainId);
297
            if ($model === null) {
298
                throw new NotFoundHttpException;
299
            }
300
301
            $model->setAttributes(current($post));
302
            $product = Yii::$container->get(Product::class);
303
            TagDependency::invalidate(Yii::$app->cache,
304
                ActiveRecordHelper::getObjectTag(get_class($product), $model->product_id));
305
            return $model->save();
306
307
308
        } else {
309
            throw new HttpException(400);
310
        }
311
    }
312
313
}
314