Completed
Push — master ( 2e8683...7e20fc )
by Igor
07:20
created

DeleteAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 21
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 11 2
1
<?php
2
3
namespace app\modules\admin\controllers\common;
4
5
use Yii;
6
use yii\base\Action;
7
use yii\web\Response;
8
use app\traits\ModelTrait;
9
10
class DeleteAction extends Action
11
{
12
    use ModelTrait;
13
14
    /**
15
     * @var string $modelClass
16
     */
17
    public $modelClass;
18
19
    public function run($id, $reload = false)
20
    {
21
        $model = new $this->modelClass;
22
        $this->findModel($model, $id)->delete();
23
24
        if ($reload) {
25
            return $this->controller->redirect(\yii\helpers\Url::to(['index']));
26
        }
27
28
        return $this->controller->asJson(true);
0 ignored issues
show
Bug introduced by
The method asJson does only exist in yii\web\Controller, but not in yii\base\Controller.

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...
29
    }
30
}
31