AdminUserDataTable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 71
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A dataTable() 0 10 1
A query() 0 6 1
A html() 0 6 1
A getColumns() 0 11 1
A getBuilderParameters() 0 6 1
1
<?php
2
3
namespace App\DataTables;
4
5
use App\Models\AdminUser;
6
use App\Support\Datatables\Services\DataTable;
7
8
class AdminUserDataTable extends DataTable
9
{
10
    /**
11
     * Build DataTable class.
12
     *
13
     * @return \Yajra\Datatables\Engines\BaseEngine
14
     */
15
    public function dataTable()
16
    {
17
        return $this->datatables
18
            ->eloquent($this->query())
19
            ->editColumn('avatar', 'datatables.admin-user-avatar')
20
            ->editColumn('action', function ($user) {
21
                return view('datatables.admin-user-action', compact('user'))->render();
0 ignored issues
show
Bug introduced by
The method render 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...
22
            })
23
            ->rawColumns(['avatar', 'action']);
24
    }
25
26
    /**
27
     * Get the query object to be processed by dataTables.
28
     *
29
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
30
     */
31
    public function query()
32
    {
33
        $query = AdminUser::query();
34
35
        return $this->applyScopes($query);
36
    }
37
38
    /**
39
     * Optional method if you want to use html builder.
40
     *
41
     * @return \Yajra\Datatables\Html\Builder
42
     */
43
    public function html()
44
    {
45
        return $this->builder()
46
            ->columns($this->getColumns())
47
            ->parameters($this->getBuilderParameters());
48
    }
49
50
    /**
51
     * Get columns.
52
     *
53
     * @return array
54
     */
55
    protected function getColumns()
56
    {
57
        return [
58
            'id' => ['title' => 'ID'],
59
            'avatar' => $this->staticColumn('avatar', ['title' => '头像']),
60
            'username' => ['title' => '用户名'],
61
            'email' => ['title' => '邮箱'],
62
            'created_at' => ['title' => '创建日期'],
63
            'action' => $this->staticColumn('action'),
64
        ];
65
    }
66
67
    /**
68
     * Get the default builder parameters.
69
     *
70
     * @return array
71
     */
72
    protected function getBuilderParameters()
73
    {
74
        return [
75
            'order' => [[0, 'asc']],
76
        ];
77
    }
78
}
79