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 — analysis-m4VopE ( 4da4ca )
by butschster
12:05
created

TableColumn::isVisible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace SleepingOwl\Admin\Display;
4
5
use Closure;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Model;
8
use InvalidArgumentException;
9
use KodiComponents\Support\HtmlAttributes;
10
use SleepingOwl\Admin\Contracts\Display\ColumnInterface;
11
use SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface;
12
use SleepingOwl\Admin\Contracts\Display\TableHeaderColumnInterface;
13
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface;
14
use SleepingOwl\Admin\Contracts\WithModelInterface;
15
use SleepingOwl\Admin\Display\Column\OrderByClause;
16
use SleepingOwl\Admin\Traits\Assets;
17
use SleepingOwl\Admin\Traits\Renderable;
18
use SleepingOwl\Admin\Traits\VisibleCondition;
19
20
abstract class TableColumn implements ColumnInterface
21
{
22
    use HtmlAttributes, Assets, Renderable, VisibleCondition;
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...
23
24
    /**
25
     * @var \Closure
26
     */
27
    protected $searchCallback = null;
28
29
    /**
30
     * @var \Closure
31
     */
32
    protected $orderCallback = null;
33
34
    /**
35
     * @var \Closure
36
     */
37
    protected $filterCallback = null;
38
39
    /**
40
     * @var null
41
     */
42
    protected $columMetaClass = null;
43
    /**
44
     * Column header.
45
     *
46
     * @var TableHeaderColumnInterface
47
     */
48
    protected $header;
49
50
    /**
51
     * Model instance currently rendering.
52
     *
53
     * @var Model
54
     */
55
    protected $model;
56
57
    /**
58
     * Column appendant.
59
     *
60
     * @var ColumnInterface
61
     */
62
    protected $append;
63
64
    /**
65
     * Column width.
66
     *
67
     * @var string
68
     */
69
    protected $width = null;
70
71
    /**
72
     * @var OrderByClauseInterface
73
     */
74
    protected $orderByClause;
75
76
    /**
77
     * @var bool
78
     */
79
    protected $isSearchable = false;
80
81
    /**
82
     * TableColumn constructor.
83
     *
84
     * @param string|null $label
85
     */
86
    public function __construct($label = null)
87
    {
88
        $this->header = app(TableHeaderColumnInterface::class);
89
90
        if (! is_null($label)) {
91
            $this->setLabel($label);
92
        }
93
94
        $this->initializePackage();
95
    }
96
97
    /**
98
     * Initialize column.
99
     */
100
    public function initialize()
101
    {
102
        $this->includePackage();
103
    }
104
105
    /**
106
     * @param $columnMetaClass
107
     * @return $this
108
     */
109
    public function setMetaData($columnMetaClass)
110
    {
111
        $this->columMetaClass = $columnMetaClass;
112
113
        return $this;
114
    }
115
116
    /**
117
     * @return mixed
118
     */
119
    public function getMetaData()
120
    {
121
        return $this->columMetaClass
122
            ? app()->make($this->columMetaClass)
123
            : false;
124
    }
125
126
    /**
127
     * @param \Closure $callable
128
     * @return $this
129
     */
130
    public function setOrderCallback(Closure $callable)
131
    {
132
        $this->orderCallback = $callable;
133
134
        return $this->setOrderable($callable);
135
    }
136
137
    /**
138
     * @param \Closure $callable
139
     * @return $this
140
     */
141
    public function setSearchCallback(Closure $callable)
142
    {
143
        $this->searchCallback = $callable;
144
145
        return $this;
146
    }
147
148
    /**
149
     * @param \Closure $callable
150
     * @return $this
151
     */
152
    public function setFilterCallback(Closure $callable)
153
    {
154
        $this->filterCallback = $callable;
155
156
        return $this;
157
    }
158
159
    /**
160
     * @return \Closure
161
     */
162
    public function getOrderCallback()
163
    {
164
        return $this->orderCallback;
165
    }
166
167
    /**
168
     * @return \Closure
169
     */
170
    public function getSearchCallback()
171
    {
172
        return $this->searchCallback;
173
    }
174
175
    /**
176
     * @return \Closure
177
     */
178
    public function getFilterCallback()
179
    {
180
        return $this->filterCallback;
181
    }
182
183
    /**
184
     * @return TableHeaderColumnInterface
185
     */
186
    public function getHeader()
187
    {
188
        return $this->header;
189
    }
190
191
    /**
192
     * @return int|string
193
     */
194
    public function getWidth()
195
    {
196
        return $this->width;
197
    }
198
199
    /**
200
     * @param int|string $width
201
     *
202
     * @return $this
203
     */
204
    public function setWidth($width)
205
    {
206
        if (is_int($width)) {
207
            $width = $width.'px';
208
        }
209
210
        $this->width = $width;
211
212
        return $this;
213
    }
214
215
    /**
216
     * @param $isSearchable
217
     *
218
     * @return TableColumn
219
     */
220
    public function setSearchable($isSearchable)
221
    {
222
        $this->isSearchable = $isSearchable;
223
224
        return $this;
225
    }
226
227
    /**
228
     * @return ColumnInterface
229
     */
230
    public function getAppends()
231
    {
232
        return $this->append;
233
    }
234
235
    /**
236
     * @param ColumnInterface $append
237
     *
238
     * @return $this
239
     */
240
    public function append(ColumnInterface $append)
241
    {
242
        $this->append = $append;
243
244
        return $this;
245
    }
246
247
    /**
248
     * @return Model $model
249
     */
250
    public function getModel()
251
    {
252
        return $this->model;
253
    }
254
255
    /**
256
     * @param Model $model
257
     *
258
     * @return $this
259
     */
260
    public function setModel(Model $model)
261
    {
262
        $this->model = $model;
263
        $append = $this->getAppends();
264
265
        if ($append instanceof WithModelInterface) {
0 ignored issues
show
introduced by
$append is always a sub-type of SleepingOwl\Admin\Contracts\WithModelInterface.
Loading history...
266
            $append->setModel($model);
267
        }
268
269
        return $this;
270
    }
271
272
    /**
273
     * Set column header label.
274
     *
275
     * @param string $title
276
     *
277
     * @return $this
278
     */
279
    public function setLabel($title)
280
    {
281
        $this->getHeader()->setTitle($title);
282
283
        return $this;
284
    }
285
286
    /**
287
     * @param OrderByClauseInterface|bool|string|\Closure $orderable
288
     * @return $this
289
     */
290
    public function setOrderable($orderable)
291
    {
292
        if ($orderable instanceof Closure || is_string($orderable)) {
293
            $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

293
            $orderable = new OrderByClause(/** @scrutinizer ignore-type */ $orderable);
Loading history...
294
        }
295
296
        if ($orderable !== false && ! $orderable instanceof OrderByClauseInterface) {
297
            throw new InvalidArgumentException('Argument must be instance of SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface interface');
298
        }
299
300
        $this->orderByClause = $orderable;
0 ignored issues
show
Documentation Bug introduced by
It seems like $orderable can also be of type boolean. 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...
301
        $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

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

369
        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...
370
            $this->getModel()
371
        );
372
    }
373
}
374