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.
Completed
Push — new ( ea2a8e...a979f7 )
by Dave
16s
created

TableColumn::isSearchable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Display;
4
5
use SleepingOwl\Admin\Traits\Assets;
6
use Illuminate\Database\Eloquent\Model;
7
use SleepingOwl\Admin\Traits\Renderable;
8
use Illuminate\Database\Eloquent\Builder;
9
use KodiComponents\Support\HtmlAttributes;
10
use SleepingOwl\Admin\Contracts\WithModelInterface;
11
use SleepingOwl\Admin\Display\Column\OrderByClause;
12
use SleepingOwl\Admin\Contracts\Display\ColumnInterface;
13
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface;
14
use SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface;
15
use SleepingOwl\Admin\Contracts\Display\TableHeaderColumnInterface;
16
17
abstract class TableColumn implements ColumnInterface
18
{
19
    use HtmlAttributes, Assets, Renderable;
0 ignored issues
show
Bug introduced by
The trait SleepingOwl\Admin\Traits\Renderable requires the property $view which is not provided by SleepingOwl\Admin\Display\TableColumn.
Loading history...
20
21
    /**
22
     * @var \Closure
23
     */
24
    protected $searchCallback = null;
25
26
    /**
27
     * @var \Closure
28
     */
29
    protected $orderCallback = null;
30
31
    /**
32
     * @var \Closure
33
     */
34
    protected $filterCallback = null;
35
36
    /**
37
     * @var null
38
     */
39
    protected $columMetaClass = null;
40
    /**
41
     * Column header.
42
     *
43
     * @var TableHeaderColumnInterface
44
     */
45
    protected $header;
46
47
    /**
48
     * Model instance currently rendering.
49
     *
50
     * @var Model
51
     */
52
    protected $model;
53
54
    /**
55
     * Column appendant.
56
     *
57
     * @var ColumnInterface
58
     */
59
    protected $append;
60
61
    /**
62
     * Column width.
63
     *
64
     * @var string
65
     */
66
    protected $width = null;
67
68
    /**
69
     * @var OrderByClauseInterface
70
     */
71
    protected $orderByClause;
72
73
    /**
74
     * @var boolean
75
     */
76
    protected $isSearchable = false;
77
78
    /**
79
     * TableColumn constructor.
80
     *
81
     * @param string|null $label
82
     */
83
    public function __construct($label = null)
84
    {
85
        $this->header = app(TableHeaderColumnInterface::class);
86
87
        if (! is_null($label)) {
88
            $this->setLabel($label);
89
        }
90
91
        $this->initializePackage();
92
    }
93
94
    /**
95
     * Initialize column.
96
     */
97
    public function initialize()
98
    {
99
        $this->includePackage();
100
    }
101
102
    /**
103
     * @param $columnMetaClass
104
     * @return $this
105
     */
106
    public function setMetaData($columnMetaClass)
107
    {
108
        $this->columMetaClass = $columnMetaClass;
109
110
        return $this;
111
    }
112
113
    /**
114
     * @return mixed
115
     */
116
    public function getMetaData()
117
    {
118
        return $this->columMetaClass
119
            ? app()->make($this->columMetaClass)
120
            : false;
121
    }
122
123
    /**
124
     * @param \Closure $callable
125
     * @return $this
126
     */
127
    public function setOrderCallback(\Closure $callable)
128
    {
129
        $this->orderCallback = $callable;
130
131
        return $this->setOrderable($callable);
0 ignored issues
show
Deprecated Code introduced by
The function SleepingOwl\Admin\Displa...eColumn::setOrderable() has been deprecated. ( Ignorable by Annotation )

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

131
        return /** @scrutinizer ignore-deprecated */ $this->setOrderable($callable);
Loading history...
132
    }
133
134
    /**
135
     * @param \Closure $callable
136
     * @return $this
137
     */
138
    public function setSearchCallback(\Closure $callable)
139
    {
140
        $this->searchCallback = $callable;
141
142
        return $this;
143
    }
144
145
    /**
146
     * @param \Closure $callable
147
     * @return $this
148
     */
149
    public function setFilterCallback(\Closure $callable)
150
    {
151
        $this->filterCallback = $callable;
152
153
        return $this;
154
    }
155
156
    /**
157
     * @return \Closure
158
     */
159
    public function getOrderCallback()
160
    {
161
        return $this->orderCallback;
162
    }
163
164
    /**
165
     * @return \Closure
166
     */
167
    public function getSearchCallback()
168
    {
169
        return $this->searchCallback;
170
    }
171
172
    /**
173
     * @return \Closure
174
     */
175
    public function getFilterCallback()
176
    {
177
        return $this->filterCallback;
178
    }
179
180
    /**
181
     * @return TableHeaderColumnInterface
182
     */
183
    public function getHeader()
184
    {
185
        return $this->header;
186
    }
187
188
    /**
189
     * @return int|string
190
     */
191
    public function getWidth()
192
    {
193
        return $this->width;
194
    }
195
196
    /**
197
     * @param int|string $width
198
     *
199
     * @return $this
200
     */
201
    public function setWidth($width)
202
    {
203
        if (is_int($width)) {
204
            $width = $width.'px';
205
        }
206
207
        $this->width = $width;
208
209
        return $this;
210
    }
211
212
    /**
213
     * @param $isSearchable
214
     *
215
     * @return TableColumn
216
     */
217
    public function setSearchable($isSearchable)
218
    {
219
        $this->isSearchable = $isSearchable;
220
221
        return $this;
222
    }
223
224
    /**
225
     * @return ColumnInterface
226
     */
227
    public function getAppends()
228
    {
229
        return $this->append;
230
    }
231
232
    /**
233
     * @param ColumnInterface $append
234
     *
235
     * @return $this
236
     */
237
    public function append(ColumnInterface $append)
238
    {
239
        $this->append = $append;
240
241
        return $this;
242
    }
243
244
    /**
245
     * @return Model $model
246
     */
247
    public function getModel()
248
    {
249
        return $this->model;
250
    }
251
252
    /**
253
     * @param Model $model
254
     *
255
     * @return $this
256
     */
257
    public function setModel(Model $model)
258
    {
259
        $this->model = $model;
260
        $append = $this->getAppends();
261
262
        if ($append instanceof WithModelInterface) {
0 ignored issues
show
introduced by
$append is always a sub-type of SleepingOwl\Admin\Contracts\WithModelInterface.
Loading history...
263
            $append->setModel($model);
264
        }
265
266
        return $this;
267
    }
268
269
    /**
270
     * Set column header label.
271
     *
272
     * @param string $title
273
     *
274
     * @return $this
275
     */
276
    public function setLabel($title)
277
    {
278
        $this->getHeader()->setTitle($title);
0 ignored issues
show
Bug introduced by
The method setTitle() does not exist on SleepingOwl\Admin\Contra...leHeaderColumnInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to SleepingOwl\Admin\Contra...leHeaderColumnInterface. ( Ignorable by Annotation )

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

278
        $this->getHeader()->/** @scrutinizer ignore-call */ setTitle($title);
Loading history...
279
280
        return $this;
281
    }
282
283
    /**
284
     * @param OrderByClauseInterface|bool|string|\Closure $orderable
285
     * @deprecated
286
     * @return $this
287
     */
288
    public function setOrderable($orderable)
289
    {
290
        if ($orderable instanceof \Closure || is_string($orderable)) {
291
            $orderable = new OrderByClause($orderable);
0 ignored issues
show
Bug introduced by
It seems like $orderable can also be of type Closure; however, parameter $name of SleepingOwl\Admin\Displa...ByClause::__construct() does only seem to accept Mockery\Matcher\Closure|string, 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

291
            $orderable = new OrderByClause(/** @scrutinizer ignore-type */ $orderable);
Loading history...
292
        }
293
294
        if ($orderable !== false && ! $orderable instanceof OrderByClauseInterface) {
295
            throw new \InvalidArgumentException('Argument must be instance of SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface interface');
296
        }
297
298
        $this->orderByClause = $orderable;
0 ignored issues
show
Documentation Bug introduced by
It seems like $orderable can also be of type false. However, the property $orderByClause is declared as type SleepingOwl\Admin\Contra...\OrderByClauseInterface. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
299
        $this->getHeader()->setOrderable($this->isOrderable());
0 ignored issues
show
Bug introduced by
The method setOrderable() does not exist on SleepingOwl\Admin\Contra...leHeaderColumnInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to SleepingOwl\Admin\Contra...leHeaderColumnInterface. ( Ignorable by Annotation )

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

299
        $this->getHeader()->/** @scrutinizer ignore-call */ setOrderable($this->isOrderable());
Loading history...
300
301
        return $this;
302
    }
303
304
    /**
305
     * @return OrderByClauseInterface
306
     */
307
    public function getOrderByClause()
308
    {
309
        return $this->orderByClause;
310
    }
311
312
    /**
313
     * Check if column is orderable.
314
     * @return bool
315
     */
316
    public function isOrderable()
317
    {
318
        return $this->orderByClause instanceof OrderByClauseInterface;
319
    }
320
321
    /**
322
     * Check if column is Searchable
323
     * @return bool
324
     */
325
    public function isSearchable()
326
    {
327
        return $this->isSearchable;
328
    }
329
330
    /**
331
     * @param Builder $query
332
     * @param string $direction
333
     * @deprecated
334
     * @return $this
335
     */
336
    public function orderBy(Builder $query, $direction)
337
    {
338
        if (! $this->isOrderable()) {
339
            throw new \InvalidArgumentException('Argument must be instance of SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface interface');
340
        }
341
342
        $this->orderByClause->modifyQuery($query, $direction);
343
344
        return $this;
345
    }
346
347
    /**
348
     * Get the instance as an array.
349
     *
350
     * @return array
351
     */
352
    public function toArray()
353
    {
354
        return [
355
            'attributes' => $this->htmlAttributesToString(),
356
            'model'      => $this->getModel(),
357
            'append'     => $this->getAppends(),
358
        ];
359
    }
360
361
    /**
362
     * Get related model configuration.
363
     * @return ModelConfigurationInterface
364
     */
365
    protected function getModelConfiguration()
366
    {
367
        return app('sleeping_owl')->getModel(
0 ignored issues
show
Bug introduced by
The method getModel() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

367
        return app('sleeping_owl')->/** @scrutinizer ignore-call */ getModel(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
368
            $this->getModel()
369
        );
370
    }
371
}
372