Completed
Push — master ( 0ba9c9...c4f173 )
by jxlwqq
15s queued 11s
created

src/Actions/GridAction.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Encore\Admin\Actions;
4
5
use Encore\Admin\Grid;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
use Illuminate\Http\Request;
8
9
/**
10
 * Class GridAction.
11
 *
12
 * @method retrieveModel(Request $request)
13
 */
14
abstract class GridAction extends Action
15
{
16
    /**
17
     * @var Grid
18
     */
19
    protected $parent;
20
21
    /**
22
     * @var string
23
     */
24
    public $selectorPrefix = '.grid-action-';
25
26
    /**
27
     * @param Grid $grid
28
     *
29
     * @return $this
30
     */
31
    public function setGrid(Grid $grid)
32
    {
33
        $this->parent = $grid;
34
35
        return $this;
36
    }
37
38
    /**
39
     * Get url path of current resource.
40
     *
41
     * @return string
42
     */
43
    public function getResource()
44
    {
45
        return $this->parent->resource();
46
    }
47
48
    /**
49
     * @return mixed
50
     */
51
    protected function getModelClass()
52
    {
53
        $model = $this->parent->model()->getOriginalModel();
0 ignored issues
show
The method getOriginalModel does only exist in Encore\Admin\Grid\Model, but not in Illuminate\Database\Eloquent\Builder.

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...
54
55
        return str_replace('\\', '_', get_class($model));
56
    }
57
58
    /**
59
     * @return array
60
     */
61
    public function parameters()
62
    {
63
        return ['_model' => $this->getModelClass()];
64
    }
65
66
    /**
67
     * Indicates if model uses soft-deletes.
68
     *
69
     * @param $modelClass
70
     *
71
     * @return bool
72
     */
73
    protected function modelUseSoftDeletes($modelClass)
74
    {
75
        return in_array(SoftDeletes::class, class_uses_deep($modelClass));
76
    }
77
}
78