PermissionsDataTable   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 99
rs 10
c 0
b 0
f 0
wmc 6
lcom 2
cbo 5

6 Methods

Rating   Name   Duplication   Size   Complexity  
A ajax() 0 17 1
A query() 0 4 1
A html() 0 8 1
A getColumns() 0 19 1
A getBuilderParameters() 0 17 1
A filename() 0 4 1
1
<?php
2
3
namespace Yajra\CMS\DataTables;
4
5
use Yajra\Acl\Models\Permission;
6
use Yajra\Datatables\Services\DataTable;
7
8
class PermissionsDataTable extends DataTable
9
{
10
    /**
11
     * @return \Illuminate\Http\JsonResponse
12
     */
13
    public function ajax()
14
    {
15
        return $this->datatables
16
            ->eloquent($this->query())
17
            ->addColumn('roles', function (Permission $permission) {
18
                return view('administrator.permissions.datatables.roles', compact('permission'))->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...
19
            })
20
            ->editColumn('system', function (Permission $permission) {
21
                return dt_check($permission->system);
22
            })
23
            ->editColumn('slug', function (Permission $permission) {
24
                return '<small>' . $permission->slug . '</small>';
25
            })
26
            ->addColumn('action', 'administrator.permissions.datatables.action')
27
            ->rawColumns(['roles', 'system', 'slug', 'action'])
28
            ->make(true);
29
    }
30
31
    /**
32
     * @return \Illuminate\Database\Eloquent\Builder
33
     */
34
    public function query()
35
    {
36
        return Permission::query();
37
    }
38
39
    /**
40
     * @return \Yajra\Datatables\Html\Builder
41
     */
42
    public function html()
43
    {
44
        return $this
45
            ->builder()
46
            ->columns($this->getColumns())
47
            ->addAction(['width' => '60px'])
48
            ->parameters($this->getBuilderParameters());
49
    }
50
51
    /**
52
     * @return array
53
     */
54
    private function getColumns()
55
    {
56
        return [
57
            'id',
58
            'resource',
59
            'name',
60
            'slug',
61
            'system' => ['class' => 'text-center', 'width' => '30px', 'title' => 'Sys'],
62
            'roles'  => [
63
                'class'      => 'text-center',
64
                'width'      => '30px',
65
                'searchable' => false,
66
                'orderable'  => false,
67
                'printable'  => false,
68
            ],
69
            'created_at',
70
            'updated_at',
71
        ];
72
    }
73
74
    /**
75
     * Get builder params.
76
     *
77
     * @return array
78
     */
79
    protected function getBuilderParameters()
80
    {
81
        return array_merge_recursive(['buttons' => ['resource']], [
82
            'order'     => [[0, 'desc']],
83
            'buttons'   => [
84
                [
85
                    'extend' => 'create',
86
                    'text'   => '<i class="fa fa-plus"></i>&nbsp;&nbsp;' . trans('cms::permission.datatable.buttons.create'),
87
                ],
88
                'export',
89
                'print',
90
                'reset',
91
                'reload',
92
            ],
93
            'stateSave' => true,
94
        ]);
95
    }
96
97
    /**
98
     * Get filename for export.
99
     *
100
     * @return string
101
     */
102
    protected function filename()
103
    {
104
        return 'permissions';
105
    }
106
}
107