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 ( 7a24d5...09959f )
by Cristian
02:56
created

AjaxTable::search()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 44
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 23
nc 1
nop 0
dl 0
loc 44
rs 8.5806
c 1
b 1
f 0
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
        // crate an array with the names of the searchable columns
16
        $columns = collect($this->crud->columns)
17
                    ->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...
18
                        // the select_multiple columns are not searchable
19
                        return isset($column['type']) && $column['type'] == 'select_multiple';
20
                    })
21
                    ->pluck('name')
22
                    // add the primary key, otherwise the buttons won't work
23
                    ->merge($this->crud->model->getKeyName())
24
                    ->toArray();
25
26
        // structure the response in a DataTable-friendly way
27
        $dataTable = new \LiveControl\EloquentDataTable\DataTable($this->crud->query, $columns);
28
29
        // make the datatable use the column types instead of just echoing the text
30
        $dataTable->setFormatRowFunction(function ($entry) {
31
            // get the actual HTML for each row's cell
32
            $row_items = $this->crud->getRowViews($entry, $this->crud);
33
34
            // add the buttons as the last column
35
            if ($this->crud->buttons->where('stack', 'line')->count()) {
36
                $row_items[] = \View::make('crud::inc.button_stack', ['stack' => 'line'])
37
                                ->with('crud', $this->crud)
38
                                ->with('entry', $entry)
39
                                ->render();
40
            }
41
42
            // add the details_row buttons as the first column
43
            if ($this->crud->details_row) {
44
                array_unshift($row_items, \View::make('crud::columns.details_row_button')
45
                                ->with('crud', $this->crud)
46
                                ->with('entry', $entry)
47
                                ->render());
48
            }
49
50
            return $row_items;
51
        });
52
53
        return $dataTable->make();
54
    }
55
56
}