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

Test Setup Failed
Push — master ( 775b4e...bb1f8b )
by Cristian
32:16 queued 15:14
created

Query::orderBy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\CRUD\app\Library\CrudPanel\Traits;
4
5
trait Query
6
{
7
    public $query;
8
9
    // ----------------
10
    // ADVANCED QUERIES
11
    // ----------------
12
13
    /**
14
     * Add another clause to the query (for ex, a WHERE clause).
15
     *
16
     * Examples:
17
     * $this->crud->addClause('active');
18
     * $this->crud->addClause('type', 'car');
19
     * $this->crud->addClause('where', 'name', '==', 'car');
20
     * $this->crud->addClause('whereName', 'car');
21
     * $this->crud->addClause('whereHas', 'posts', function($query) {
22
     *     $query->activePosts();
23
     * });
24
     *
25
     * @param callable $function
26
     *
27
     * @return mixed
28
     */
29
    public function addClause($function)
30
    {
31
        return call_user_func_array([$this->query, $function], array_slice(func_get_args(), 1));
32
    }
33
34
    /**
35
     * Use eager loading to reduce the number of queries on the table view.
36
     *
37
     * @param array|string $entities
38
     *
39
     * @return \Illuminate\Database\Eloquent\Builder
40
     */
41
    public function with($entities)
42
    {
43
        return $this->query->with($entities);
44
    }
45
46
    /**
47
     * Order the results of the query in a certain way.
48
     *
49
     * @param string $field
50
     * @param string $order
51
     *
52
     * @return \Illuminate\Database\Eloquent\Builder
53
     */
54
    public function orderBy($field, $order = 'asc')
55
    {
56
        if ($this->getRequest()->has('order')) {
0 ignored issues
show
Bug introduced by
It seems like getRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        if ($this->/** @scrutinizer ignore-call */ getRequest()->has('order')) {
Loading history...
57
            return $this->query;
58
        }
59
60
        return $this->query->orderBy($field, $order);
61
    }
62
63
    /**
64
     * Order results of the query in a custom way.
65
     *
66
     * @param array  $column           Column array with all attributes
67
     * @param string $column_direction ASC or DESC
68
     *
69
     * @return \Illuminate\Database\Eloquent\Builder
70
     */
71
    public function customOrderBy($column, $columnDirection = 'asc')
72
    {
73
        if (! isset($column['orderLogic'])) {
74
            return $this->query;
75
        }
76
77
        $this->query->getQuery()->orders = null;
78
79
        $orderLogic = $column['orderLogic'];
80
81
        if (is_callable($orderLogic)) {
82
            return $orderLogic($this->query, $column, $columnDirection);
83
        }
84
85
        return $this->query;
86
    }
87
88
    /**
89
     * Group the results of the query in a certain way.
90
     *
91
     * @param string $field
92
     *
93
     * @return \Illuminate\Database\Eloquent\Builder
94
     */
95
    public function groupBy($field)
96
    {
97
        return $this->query->groupBy($field);
98
    }
99
100
    /**
101
     * Limit the number of results in the query.
102
     *
103
     * @param int $number
104
     *
105
     * @return \Illuminate\Database\Eloquent\Builder
106
     */
107
    public function limit($number)
108
    {
109
        return $this->query->limit($number);
110
    }
111
112
    /**
113
     * Take a certain number of results from the query.
114
     *
115
     * @param int $number
116
     *
117
     * @return \Illuminate\Database\Eloquent\Builder
118
     */
119
    public function take($number)
120
    {
121
        return $this->query->take($number);
122
    }
123
124
    /**
125
     * Start the result set from a certain number.
126
     *
127
     * @param int $number
128
     *
129
     * @return \Illuminate\Database\Eloquent\Builder
130
     */
131
    public function skip($number)
132
    {
133
        return $this->query->skip($number);
134
    }
135
136
    /**
137
     * Count the number of results.
138
     *
139
     * @return int
140
     */
141
    public function count()
142
    {
143
        return $this->query->count();
144
    }
145
146
    public function orderByWithPrefix($column_name, $column_direction = 'ASC')
147
    {
148
        if ($this->driverIsSql()) {
0 ignored issues
show
Bug introduced by
It seems like driverIsSql() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

148
        if ($this->/** @scrutinizer ignore-call */ driverIsSql()) {
Loading history...
149
            return $this->query->orderByRaw($this->model->getTableWithPrefix().'.'.$column_name.' '.$column_direction);
150
        }
151
152
        return $this->query->orderBy($column_name, $column_direction);
153
    }
154
}
155