Completed
Push — master ( e3a629...db5cbc )
by Maxime
120:12 queued 118:24
created

DatatableStateTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 44
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndexDatatable() 0 9 1
A getDatatable() 0 7 1
1
<?php
2
3
namespace Distilleries\DatatableBuilder\States;
4
5
trait DatatableStateTrait
6
{
7
    /**
8
     * Datatable (injected by the constructor).
9
     *
10
     * @var \Distilleries\DatatableBuilder\EloquentDatatable $datatable
11
     */
12
    protected $datatable;
13
14
    /**
15
     * Model (injected by the contructor).
16
     *
17
     * @var \Illuminate\Database\Eloquent\Model $model
18
     */
19
    protected $model;
20
21
    /**
22
     * View to display datatable.
23
     *
24
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
25
     */
26 8
    public function getIndexDatatable()
27
    {
28 8
        $this->datatable->build();
29 8
        $datatable = $this->datatable->generateHtmlRender();
30
31 8
        return view('datatable-builder::form.state.datatable')->with([
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
32 8
            'datatable' => $datatable,
33
        ]);
34
    }
35
36
    /**
37
     * Return generated datatable.
38
     *
39
     * @return mixed
40
     */
41 4
    public function getDatatable()
42
    {
43 4
        $this->datatable->setModel($this->model);
44 4
        $this->datatable->build();
45
46 4
        return $this->datatable->generateColomns();
47
    }
48
}
49