GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — analysis-8bGQN2 ( 8fcae0 )
by butschster
10:20 queued 32s
created

DisplayDatatablesAsync::applyOffset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 10
rs 10
1
<?php
2
3
namespace SleepingOwl\Admin\Display;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Support\Collection;
7
use Illuminate\Support\Facades\Request;
8
use SleepingOwl\Admin\Display\Column\Control;
9
use SleepingOwl\Admin\Contracts\WithRoutesInterface;
10
11
class DisplayDatatablesAsync extends DisplayDatatables implements WithRoutesInterface
12
{
13
    /**
14
     * Register display routes.
15
     *
16
     * @param Router $router
17
     *
18
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
19
     */
20
    public static function registerRoutes(Router $router)
21
    {
22
        $routeName = 'admin.display.async';
23
        if (! $router->has($routeName)) {
24
            $router->get('{adminModel}/async/{adminDisplayName?}', [
25
                'as' => $routeName,
26
                'uses' => 'SleepingOwl\Admin\Http\Controllers\DisplayController@async',
0 ignored issues
show
Bug introduced by
The controller App\Http\Controllers\Sle...llers\DisplayController does not seem to exist.

If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed.

If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed:

$app->group(['as' => 'foo', 'prefix' => 'foo', 'namespace' => 'Foo'], function($app) {
    $app->group(['as' => 'foo', 'prefix' => 'foo'], function($app) {
        $app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'FooController@getFoo']);
        $app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'BarController@getBar']);
    });
});
Loading history...
27
            ]);
28
        }
29
30
        $routeName = 'admin.display.async.inlineEdit';
31
        if (! $router->has($routeName)) {
32
            $router->post('{adminModel}/async/{adminDisplayName?}', [
33
                'as' => $routeName,
34
                'uses' => 'SleepingOwl\Admin\Http\Controllers\AdminController@inlineEdit',
0 ignored issues
show
Bug introduced by
The controller App\Http\Controllers\Sle...rollers\AdminController does not seem to exist.

If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed.

If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed:

$app->group(['as' => 'foo', 'prefix' => 'foo', 'namespace' => 'Foo'], function($app) {
    $app->group(['as' => 'foo', 'prefix' => 'foo'], function($app) {
        $app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'FooController@getFoo']);
        $app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'BarController@getBar']);
    });
});
Loading history...
35
            ]);
36
        }
37
    }
38
39
    protected $payload;
40
    /**
41
     * @var string
42
     */
43
    protected $name;
44
45
    /**
46
     * @param string|null $name
47
     */
48
    protected $distinct;
49
50
    /**
51
     * @var
52
     */
53
    protected $displaySearch = false;
54
55
    /**
56
     * @var
57
     */
58
    protected $displayLength = false;
59
60
    /**
61
     * DisplayDatatablesAsync constructor.
62
     *
63
     * @param string|null $name
64
     * @param string|null $distinct
65
     */
66
    public function __construct($name = null, $distinct = null)
67
    {
68
        parent::__construct();
69
70
        $this->setName($name);
71
        $this->setDistinct($distinct);
72
73
        $this->getColumns()->setView('display.extensions.columns_async');
74
    }
75
76
    /**
77
     * Initialize display.
78
     */
79
    public function initialize()
80
    {
81
        parent::initialize();
82
83
        $attributes = Request::all();
84
        array_unshift($attributes, $this->getName());
85
        array_unshift($attributes, $this->getModelConfiguration()->getAlias());
86
87
        $this->setHtmlAttribute('style', 'width:100%');
88
        $this->setHtmlAttribute('data-url', route('admin.display.async', $attributes));
89
        $this->setHtmlAttribute('data-payload', json_encode($this->payload));
90
91
        if ($this->getDisplaySearch()) {
92
            $this->setHtmlAttribute('data-display-search', 1);
93
        }
94
95
        if ($this->getDisplayLength()) {
96
            $this->setHtmlAttribute('data-display-dtlength', 1);
97
        }
98
    }
99
100
    /**
101
     * @param bool $length
102
     * @return $this
103
     */
104
    public function setDisplayLength($length)
105
    {
106
        $this->displayLength = $length;
107
108
        return $this;
109
    }
110
111
    /**
112
     * @return bool
113
     */
114
    public function getDisplayLength()
115
    {
116
        return $this->displayLength;
117
    }
118
119
    /**
120
     * @param $search
121
     * @return $this
122
     */
123
    public function setDisplaySearch($search)
124
    {
125
        $this->displaySearch = $search;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @return bool
132
     */
133
    public function getDisplaySearch()
134
    {
135
        return $this->displaySearch;
136
    }
137
138
    /**
139
     * @return string
140
     */
141
    public function getName()
142
    {
143
        return $this->name;
144
    }
145
146
    /**
147
     * @param string $name
148
     *
149
     * @return $this
150
     */
151
    public function setName($name)
152
    {
153
        $this->name = $name;
154
155
        return $this;
156
    }
157
158
    /**
159
     * @return mixed
160
     */
161
    public function getDistinct()
162
    {
163
        return $this->distinct;
164
    }
165
166
    /**
167
     * @param mixed $distinct
168
     *
169
     * @return $this
170
     */
171
    public function setDistinct($distinct)
172
    {
173
        $this->distinct = $distinct;
174
175
        return $this;
176
    }
177
178
    /**
179
     * Render async request.
180
     *
181
     * @param \Illuminate\Http\Request $request
182
     *
183
     * @return array
184
     */
185
    public function renderAsync(\Illuminate\Http\Request $request)
186
    {
187
        $query = $this->getRepository()->getQuery();
188
        $totalCount = $query->count();
189
        $filteredCount = 0;
190
191
        if (! is_null($this->distinct)) {
192
            $filteredCount = $query->distinct()->count($this->getDistinct());
193
        }
194
195
        $this->modifyQuery($query);
196
        $this->applySearch($query, $request);
197
198
        if (is_null($this->distinct)) {
199
            $countQuery = clone $query;
200
            $countQuery->getQuery()->orders = null;
201
            $filteredCount = $countQuery->count();
202
        }
203
204
        $this->applyOffset($query, $request);
0 ignored issues
show
Bug introduced by
$query of type Illuminate\Database\Eloquent\Builder is incompatible with the type Illuminate\Database\Query\Builder expected by parameter $query of SleepingOwl\Admin\Displa...layTable::applyOffset(). ( Ignorable by Annotation )

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

204
        $this->applyOffset(/** @scrutinizer ignore-type */ $query, $request);
Loading history...
205
        $collection = $query->get();
206
207
        return $this->prepareDatatablesStructure($request, $collection, $totalCount, $filteredCount);
0 ignored issues
show
Bug introduced by
It seems like $totalCount can also be of type Illuminate\Database\Eloquent\Builder; however, parameter $totalCount of SleepingOwl\Admin\Displa...reDatatablesStructure() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

207
        return $this->prepareDatatablesStructure($request, $collection, /** @scrutinizer ignore-type */ $totalCount, $filteredCount);
Loading history...
208
    }
209
210
    /**
211
     * Convert collection to the datatables structure.
212
     *
213
     * @param \Illuminate\Http\Request $request
214
     * @param array|Collection $collection
215
     * @param int $totalCount
216
     * @param int $filteredCount
217
     *
218
     * @return array
219
     */
220
    protected function prepareDatatablesStructure(
221
        \Illuminate\Http\Request $request,
222
        Collection $collection,
223
        $totalCount,
224
        $filteredCount
225
    ) {
226
        $columns = $this->getColumns();
227
228
        $result = [];
229
        $result['draw'] = $request->input('draw', 0);
230
        $result['recordsTotal'] = $totalCount;
231
        $result['recordsFiltered'] = $filteredCount;
232
        $result['data'] = [];
233
234
        foreach ($collection as $instance) {
235
            $_row = [];
236
237
            foreach ($columns->all() as $column) {
238
                $column->setModel($instance);
239
240
                if ($column instanceof Control) {
241
                    $column->initialize();
242
                }
243
244
                $_row[] = (string) $column;
245
            }
246
247
            $result['data'][] = $_row;
248
        }
249
250
        return $result;
251
    }
252
253
    /**
254
     * @return void
255
     */
256
    public function getCollection()
257
    {
258
    }
259
260
    /**
261
     * @param $payload
262
     */
263
    public function setPayload($payload)
264
    {
265
        $this->payload = $payload;
266
    }
267
268
    /**
269
     * @return mixed
270
     */
271
    public function getPayload()
272
    {
273
        return $this->payload;
274
    }
275
276
    /**
277
     * @return array
278
     * @throws \Exception
279
     */
280
    public function toArray()
281
    {
282
        $params = parent::toArray();
283
        $params['payload'] = $this->payload;
284
285
        return $params;
286
    }
287
}
288