DeleteBatch   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 18 5
1
<?php
2
3
4
namespace carono\yii2crud\actions;
5
6
use carono\yii2crud\CrudController;
7
use Yii;
8
9
/**
10
 * Class DeleteBatch
11
 *
12
 * @package carono\yii2crud\actions
13
 * @property CrudController $controller
14
 */
15
class DeleteBatch extends Action
16
{
17
    public function run(array $ids)
18
    {
19
        $errors = [];
20
        foreach ($ids as $id) {
21
            $this->controller->runAction('delete', ['id' => $id]);
22
            if (Yii::$app->session->hasFlash('error')) {
0 ignored issues
show
Bug introduced by
The method hasFlash() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
            if (Yii::$app->session->/** @scrutinizer ignore-call */ hasFlash('error')) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
                $errors[] = Yii::$app->session->getFlash('error', null, true);
24
            }
25
        }
26
        if (!empty($errors)) {
27
            Yii::$app->session->removeFlash('success');
28
            Yii::$app->session->setFlash('error', implode('<br>', $errors));
29
        }
30
        if (Yii::$app->request->isAjax) {
31
            return Yii::$app->response->redirect(Yii::$app->request->referrer, 302, false);
32
        }
33
34
        return $this->controller->redirect($this->controller->deleteBatchRedirect());
35
    }
36
}