Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 54fb66...bd2bad )
by Cristian
11:17
created

AjaxTable::search()   C

Complexity

Conditions 8
Paths 40

Size

Total Lines 42
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 20
nc 40
nop 0
dl 0
loc 42
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Http\Controllers\CrudFeatures;
4
5
trait AjaxTable
6
{
7
    /**
8
     * The search function that is called by the data table.
9
     *
10
     * @return  JSON Array of cells in HTML form.
11
     */
12
    public function search()
13
    {
14
        $this->crud->hasAccessOrFail('list');
0 ignored issues
show
Bug introduced by
The property crud does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
15
16
        $totalRows = $filteredRows = $this->crud->count();
17
18
        // if a search term was present
19
        if ($this->request->input('search') && $this->request->input('search')['value']) {
20
            // filter the results accordingly
21
            $this->crud->applySearchTerm($this->request->input('search')['value']);
0 ignored issues
show
Bug introduced by
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
            // recalculate the number of filtered rows
23
            $filteredRows = $this->crud->count();
24
        }
25
26
        // start the results according to the datatables pagination
27
        if ($this->request->input('start')) {
28
            $this->crud->skip($this->request->input('start'));
29
        }
30
31
        // limit the number of results according to the datatables pagination
32
        if ($this->request->input('length')) {
33
            $this->crud->take($this->request->input('length'));
34
        }
35
36
        // overwrite any order set in the setup() method with the datatables order
37
        if ($this->request->input('order')) {
38
            $column_number = $this->request->input('order')[0]['column'];
39
            if ($this->crud->details_row) {
40
                $column_number = $column_number - 1;
0 ignored issues
show
Coding Style introduced by
Decrement operators should be used where possible; found "$column_number = $column_number - 1;" but expected "$column_number--"
Loading history...
41
            }
42
            $column_direction = $this->request->input('order')[0]['dir'];
43
            $column = $this->crud->findColumnById($column_number);
44
45
            if ($column['tableColumn']) {
46
                $this->crud->orderBy($column['name'], $column_direction);
47
            }
48
        }
49
50
        $entries = $this->crud->getEntries();
51
52
        return $this->crud->getEntriesAsJsonForDatatables($entries, $totalRows, $filteredRows);
53
    }
54
}
55