ImportLogsDataTable   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 1
dl 0
loc 88
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A query() 0 6 1
A ajax() 0 6 1
A getBuilderParameters() 0 31 1
A getColumns() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Foundation\DataTables;
6
7
use Cortex\Foundation\Models\Log;
8
use Cortex\Foundation\Transformers\LogTransformer;
9
10
/**
11
 * @property string $resource
12
 * @property string $tabs
13
 * @property string $id
14
 */
15
class ImportLogsDataTable extends AbstractDataTable
16
{
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $model = Log::class;
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    protected $transformer = LogTransformer::class;
26
27
    /**
28
     * Get the query object to be processed by dataTables.
29
     *
30
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Illuminate\Database\Que...tabase\Eloquent\Builder.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
31
     */
32
    public function query()
33
    {
34
        $query = Log::where('description', 'imported')->where('subject_type', $this->resource);
35
36
        return $this->applyScopes($query);
37
    }
38
39
    /**
40
     * Display ajax response.
41
     *
42
     * @return \Illuminate\Http\JsonResponse
43
     */
44
    public function ajax()
45
    {
46
        return datatables($this->query())
0 ignored issues
show
Bug introduced by
The method setTransformer does only exist in Yajra\DataTables\DataTableAbstract, but not in Yajra\DataTables\DataTables.

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...
47
            ->setTransformer(app($this->transformer))
48
            ->make(true);
49
    }
50
51
    /**
52
     * Get default builder parameters.
53
     *
54
     * @return array
55
     */
56
    protected function getBuilderParameters(): array
57
    {
58
        return [
59
            'dom' => $this->dom,
60
            'keys' => $this->keys,
61
            'order' => $this->order,
62
            'retrieve' => $this->retrieve,
63
            'autoWidth' => $this->autoWidth,
64
            'drawCallback' => "function (settings) {
65
                var api = this.api();
66
67
                $('#{$this->id} tbody td.dt-details-control').on('click', function () {
68
                    var tr = $(this).closest('tr');
69
                    var row = api.row(tr);
70
71
                    if (row.child.isShown()) {
72
                        row.child.hide();
73
                        tr.removeClass('shown');
74
                    } else {
75
                        row.child(dtFormatLogDetails(row.data().properties)).show();
76
                        tr.addClass('shown');
77
                    }
78
                });
79
            }",
80
            'buttons' => [
81
                'print', 'reset', 'reload', 'export',
82
                ['extend' => 'colvis', 'text' => '<i class="fa fa-columns"></i> '.trans('cortex/foundation::common.columns').' <span class="caret"/>'],
83
                ['extend' => 'pageLength', 'text' => '<i class="fa fa-list-ol"></i> '.trans('cortex/foundation::common.limit').' <span class="caret"/>'],
84
            ],
85
        ];
86
    }
87
88
    /**
89
     * Get columns.
90
     *
91
     * @return array
92
     */
93
    protected function getColumns(): array
94
    {
95
        return [
96
            'details' => ['title' => '', 'data' => null, 'defaultContent' => '', 'class' => 'dt-details-control', 'searchable' => false, 'orderable' => false],
97
            'causer' => ['title' => trans('cortex/foundation::common.causer'), 'name' => 'causer.username', 'searchable' => false, 'orderable' => false, 'render' => 'full.causer_route ? "<a href=\""+full.causer_route+"\">"+data+"</a>" : data', 'responsivePriority' => 0],
98
            'description' => ['title' => trans('cortex/foundation::common.description'), 'orderable' => false],
99
            'created_at' => ['title' => trans('cortex/foundation::common.date'), 'render' => "moment(data).format('YYYY-MM-DD, hh:mm:ss A')"],
100
        ];
101
    }
102
}
103