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
Pull Request — master (#943)
by Pascal
02:48
created

AjaxTable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B search() 0 36 3
A searchableColumns() 0 23 1
1
<?php
2
3
namespace Backpack\CRUD\app\Http\Controllers\CrudFeatures;
4
5
trait AjaxTable
6
{
7
    /**
8
     * Respond with the JSON of one or more rows, depending on the POST parameters.
9
     * @return JSON Array of cells in HTML form.
0 ignored issues
show
Documentation introduced by
Should the return type not be array? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
10
     */
11
    public function search()
12
    {
13
        $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...
14
15
        // create an array with the names of the searchable columns
16
        $columns = $this->searchableColumns();
17
18
        // structure the response in a DataTable-friendly way
19
        $dataTable = new \LiveControl\EloquentDataTable\DataTable($this->crud->query, $columns);
20
21
        // make the datatable use the column types instead of just echoing the text
22
        $dataTable->setFormatRowFunction(function ($entry) {
23
            // get the actual HTML for each row's cell
24
            $row_items = $this->crud->getRowViews($entry, $this->crud);
25
26
            // add the buttons as the last column
27
            if ($this->crud->buttons->where('stack', 'line')->count()) {
28
                $row_items[] = \View::make('crud::inc.button_stack', ['stack' => 'line'])
29
                                ->with('crud', $this->crud)
30
                                ->with('entry', $entry)
31
                                ->render();
32
            }
33
34
            // add the details_row buttons as the first column
35
            if ($this->crud->details_row) {
36
                array_unshift($row_items, \View::make('crud::columns.details_row_button')
37
                                ->with('crud', $this->crud)
38
                                ->with('entry', $entry)
39
                                ->render());
40
            }
41
42
            return $row_items;
43
        });
44
45
        return $dataTable->make();
46
    }
47
48
    /**
49
     * Gets the searchable columns
50
     *
51
     * @return array
52
     */
53
    protected function searchableColumns()
54
    {
55
        // create an array with the names of the searchable columns
56
        $columns = collect($this->crud->columns)
57
            // Excludes fields that are not searchable
58
            ->reject(function ($column, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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...
59
                return array_get($column, 'searchable', true) === false;
60
            })
61
            // Excludes fields on a relation
62
            ->reject(function ($column, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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...
63
                return array_key_exists('entity', $column);
64
            })
65
            // Excludes field types with no column
66
            ->reject(function ($column, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key 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...
67
                return in_array(array_get($column, 'type'), ['select_multiple', 'model_function', 'model_function_attribute']);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 127 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
68
            })
69
            ->pluck('name')
70
            // add the primary key, otherwise the buttons won't work
71
            ->merge($this->crud->model->getKeyName())
72
            ->toArray();
73
74
        return $columns;
75
    }
76
}
77