UpdateAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 2
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 4
1
<?php
2
3
namespace carono\yii2crud\actions;
4
5
use carono\yii2crud\CrudController;
6
use yii\helpers\Html;
7
use Yii;
8
9
/**
10
 * Class UpdateAction
11
 *
12
 * @package carono\yii2crud\actions
13
 * @property CrudController $controller
14
 * @method getMessageOnUpdate(\yii\db\ActiveRecord $model)
15
 */
16
class UpdateAction extends Action
17
{
18
    public $view = 'update';
19
    public $messageOnUpdate = 'Model Successful Updated';
20
21
    public function run($id)
22
    {
23
        $model = $this->controller->findModel($id, $this->controller->updateClass);
24
        if ($model->load(Yii::$app->request->post())) {
25
            if ($model->save()) {
26
                Yii::$app->session->setFlash('success', $this->getMessageOnUpdate($model));
0 ignored issues
show
Bug introduced by
The method setFlash() 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

26
                Yii::$app->session->/** @scrutinizer ignore-call */ 
27
                                    setFlash('success', $this->getMessageOnUpdate($model));

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...
27
                $url = $this->controller->updateRedirect($model);
28
                if (Yii::$app->request->isPjax) {
29
                    return Yii::$app->response->redirect($url, 302, false);
30
                }
31
                return $this->controller->redirect($url);
32
            }
33
            Yii::$app->session->setFlash('error', Html::errorSummary($model));
34
        }
35
        return $this->controller->render($this->view, ['model' => $model]);
36
    }
37
}