1 | <?php |
||||
2 | |||||
3 | |||||
4 | namespace carono\yii2crud\actions; |
||||
5 | |||||
6 | use carono\yii2crud\CrudController; |
||||
7 | use Yii; |
||||
8 | use yii\db\ActiveRecord; |
||||
9 | |||||
10 | /** |
||||
11 | * Class DeleteAction |
||||
12 | * |
||||
13 | * @package carono\yii2crud\actions |
||||
14 | * @property CrudController $controller |
||||
15 | * @method getMessageOnDelete() |
||||
16 | */ |
||||
17 | class DeleteAction extends Action |
||||
18 | { |
||||
19 | public $softDeleteAttribute = 'deleted_at'; |
||||
20 | public $preventAjaxRedirect = false; |
||||
21 | public $messageOnDelete = 'Model deleted'; |
||||
22 | |||||
23 | public function run($id) |
||||
24 | { |
||||
25 | $model = $this->controller->findModel($id); |
||||
26 | $model->delete(); |
||||
27 | if ($model->hasErrors() || $this->hasSoftDeleteError($model)) { |
||||
28 | $msg = current($model->getFirstErrors()); |
||||
29 | Yii::$app->session->setFlash('error', $msg ?: Yii::t('errors', 'Fail Deleting Model')); |
||||
0 ignored issues
–
show
|
|||||
30 | } else { |
||||
31 | Yii::$app->session->setFlash('success', $this->getMessageOnDelete($model)); |
||||
0 ignored issues
–
show
The call to
carono\yii2crud\actions\...n::getMessageOnDelete() has too many arguments starting with $model .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||
32 | } |
||||
33 | |||||
34 | if (Yii::$app->request->isAjax && !$this->preventAjaxRedirect) { |
||||
35 | return Yii::$app->response->redirect($this->controller->deleteRedirect($model), 302, false); |
||||
36 | } |
||||
37 | |||||
38 | return $this->controller->redirect($this->controller->deleteRedirect($model)); |
||||
39 | } |
||||
40 | |||||
41 | /** |
||||
42 | * @param ActiveRecord $model |
||||
43 | * @return bool |
||||
44 | */ |
||||
45 | public function hasSoftDeleteError($model): bool |
||||
46 | { |
||||
47 | if ($model->hasAttribute($this->softDeleteAttribute)) { |
||||
48 | return empty($model->{$this->softDeleteAttribute}); |
||||
49 | } |
||||
50 | return false; |
||||
51 | } |
||||
52 | } |
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.