Completed
Pull Request — master (#68)
by Brandon
09:40
created

ActivityLogDataTable::dataTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace App\DataTables;
4
5
use App\User;
6
use Yajra\DataTables\Services\DataTable;
7
use Spatie\Activitylog\Models\Activity;
8
9
class ActivityLogDataTable extends DataTable
10
{
11
    /**
12
     * Build DataTable class.
13
     *
14
     * @param mixed $query Results from query() method.
15
     * @return \Yajra\DataTables\DataTableAbstract
16
     */
17
    public function dataTable($query)
18
    {
19
        return datatables($query);
0 ignored issues
show
Bug Compatibility introduced by
The expression datatables($query); of type Yajra\DataTables\DataTab...a\DataTables\DataTables adds the type Yajra\DataTables\DataTables to the return on line 19 which is incompatible with the return type documented by App\DataTables\ActivityLogDataTable::dataTable of type Yajra\DataTables\DataTableAbstract.
Loading history...
20
            //->addColumn('action', 'activitylog.action');
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
    }
22
23
    /**
24
     * Get query source of dataTable.
25
     *
26
     * @param \App\User $model
27
     * @return \Illuminate\Database\Eloquent\Builder
28
     */
29
    public function query(User $model)
0 ignored issues
show
Unused Code introduced by
The parameter $model is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        //return $model->newQuery()->select($this->getColumns());
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
32
        $query = Activity::all();
33
        
34
        return $this->applyScopes($query);
0 ignored issues
show
Bug introduced by
It seems like $query defined by \Spatie\Activitylog\Models\Activity::all() on line 32 can also be of type array<integer,object<Ill...base\Eloquent\Builder>>; however, Yajra\DataTables\Services\DataTable::applyScopes() does only seem to accept object<Illuminate\Databa...abase\Eloquent\Builder>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
Bug Compatibility introduced by
The expression $this->applyScopes($query); of type Illuminate\Database\Quer...tabase\Eloquent\Builder adds the type Illuminate\Database\Query\Builder to the return on line 34 which is incompatible with the return type documented by App\DataTables\ActivityLogDataTable::query of type Illuminate\Database\Eloquent\Builder.
Loading history...
35
    }
36
37
    /**
38
     * Optional method if you want to use html builder.
39
     *
40
     * @return \Yajra\DataTables\Html\Builder
41
     */
42
    public function html()
43
    {
44
        return $this->builder()
45
                    ->columns($this->getColumns())
46
                    ->minifiedAjax()
47
                    //->addAction(['width' => '80px'])
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
                    ->parameters($this->getBuilderParameters());
49
    }
50
51
    /**
52
     * Get columns.
53
     *
54
     * @return array
55
     */
56
    protected function getColumns()
57
    {
58
        return [
59
            'id',
60
            'log_name',
61
            'description',
62
            'subject_id',
63
            'subject_type',	
64
            'causer_id',
65
            'causer_type',
66
            'properties',
67
            'created_at', 
68
            'updated_at'
69
        ];
70
    }
71
    
72
    /**
73
     * Get builder parameters.
74
     *
75
     * @return array
76
     */
77
    protected function getBuilderParameters()
78
    {
79
        return [
80
            'dom'     => 'Bfrtip',
81
            'order'   => [ [ 0, 'asc' ] ],
82
            'buttons' => [
83
                'export',
84
                'print',
85
                'reset',
86
                'reload',
87
            ],
88
            'paging' => true,
89
            'searching' => true,
90
            'info' => true,
91
            'searchDelay' => 500,
92
        ];
93
    }
94
95
    /**
96
     * Get filename for export.
97
     *
98
     * @return string
99
     */
100
    protected function filename()
101
    {
102
        return 'activitylog_' . time();
103
    }
104
}
105