RolesDataTable::html()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Yajra\CMS\DataTables;
4
5
use Yajra\Acl\Models\Role;
6
use Yajra\Datatables\Services\DataTable;
7
8
class RolesDataTable extends DataTable
9
{
10
    /**
11
     * @return \Illuminate\Http\JsonResponse
12
     */
13
    public function ajax()
14
    {
15
        return $this->datatables
16
            ->eloquent($this->query())
17
            ->editColumn('system', function (Role $role) {
18
                return dt_check($role->system);
19
            })
20
            ->addColumn('users', function (Role $role) {
21
                return view('administrator.roles.datatables.users', compact('role'))->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
            ->addColumn('permissions', function (Role $role) {
24
                return view('administrator.roles.datatables.permissions', compact('role'))->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...
25
            })
26
            ->addColumn('action', 'administrator.roles.datatables.action')
27
            ->rawColumns(['system', 'users', 'permissions', 'action'])
28
            ->make(true);
29
    }
30
31
    /**
32
     * @return \Illuminate\Database\Eloquent\Builder
33
     */
34
    public function query()
35
    {
36
        return Role::query();
37
    }
38
39
    /**
40
     * @return \Yajra\Datatables\Html\Builder
41
     */
42
    public function html()
43
    {
44
        return $this
45
            ->builder()
46
            ->columns([
47
                'id',
48
                'name',
49
                'slug',
50
                'system'      => ['class' => 'text-center', 'width' => '30px', 'title' => 'Sys'],
51
                'users'       => ['orderable' => false, 'searchable' => false, 'class' => 'text-center'],
52
                'permissions' => ['orderable' => false, 'searchable' => false, 'class' => 'text-center'],
53
                'created_at',
54
                'updated_at',
55
            ])
56
            ->addAction(['width' => '60px'])
57
            ->parameters([
58
                'stateSave' => true,
59
                'order'     => [[0, 'desc']],
60
                'buttons'   => [
61
                    [
62
                        'extend' => 'create',
63
                        'text'   => '<i class="fa fa-plus"></i>&nbsp;&nbsp;' . trans('cms::role.datatable.buttons.create'),
64
                    ],
65
                    'export',
66
                    'print',
67
                    'reset',
68
                    'reload',
69
                ],
70
            ]);
71
    }
72
}
73