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
Branch master (9e3162)
by Dave
63:34
created

TableColumn::append()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
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 bool
75
     */
76
    protected $visible = true;
77
78 45
    /**
79
     * @var bool
80 45
     */
81
    protected $isSearchable = false;
82 45
83 11
    /**
84 11
     * TableColumn constructor.
85
     *
86 45
     * @param string|null $label
87 45
     */
88
    public function __construct($label = null)
89
    {
90
        $this->header = app(TableHeaderColumnInterface::class);
91
92 2
        if (! is_null($label)) {
93
            $this->setLabel($label);
94 2
        }
95 2
96
        $this->initializePackage();
97
    }
98
99
    /**
100
     * Initialize column.
101
     */
102
    public function initialize()
103
    {
104
        $this->includePackage();
105
    }
106
107
    /**
108
     * @param $columnMetaClass
109
     * @return $this
110
     */
111
    public function setMetaData($columnMetaClass)
112
    {
113
        $this->columMetaClass = $columnMetaClass;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @return mixed
120
     */
121
    public function getMetaData()
122
    {
123
        return $this->columMetaClass
124
            ? app()->make($this->columMetaClass)
125
            : false;
126
    }
127
128
    /**
129
     * @param \Closure $callable
130
     * @return $this
131
     */
132
    public function setOrderCallback(\Closure $callable)
133
    {
134
        $this->orderCallback = $callable;
135
136
        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

136
        return /** @scrutinizer ignore-deprecated */ $this->setOrderable($callable);
Loading history...
137
    }
138
139
    /**
140
     * @param \Closure $callable
141
     * @return $this
142
     */
143
    public function setSearchCallback(\Closure $callable)
144
    {
145
        $this->searchCallback = $callable;
146
147
        return $this;
148
    }
149
150
    /**
151
     * @param \Closure $callable
152
     * @return $this
153
     */
154
    public function setFilterCallback(\Closure $callable)
155
    {
156
        $this->filterCallback = $callable;
157
158
        return $this;
159
    }
160
161
    /**
162
     * @return \Closure
163
     */
164
    public function getOrderCallback()
165
    {
166
        return $this->orderCallback;
167
    }
168
169
    /**
170
     * @return \Closure
171
     */
172
    public function getSearchCallback()
173
    {
174
        return $this->searchCallback;
175
    }
176
177
    /**
178 24
     * @return \Closure
179
     */
180 24
    public function getFilterCallback()
181
    {
182
        return $this->filterCallback;
183
    }
184
185
    /**
186 1
     * @return TableHeaderColumnInterface
187
     */
188 1
    public function getHeader()
189
    {
190
        return $this->header;
191
    }
192
193
    /**
194
     * @return int|string
195
     */
196 1
    public function getWidth()
197
    {
198 1
        return $this->width;
199 1
    }
200 1
201
    /**
202 1
     * @param int|string $width
203
     *
204 1
     * @return $this
205
     */
206
    public function setWidth($width)
207
    {
208
        if (is_int($width)) {
209
            $width = $width.'px';
210 16
        }
211
212 16
        $this->width = $width;
213
214
        return $this;
215
    }
216
217
    /**
218
     * @param $isSearchable
219
     *
220 3
     * @return TableColumn
221
     */
222 3
    public function setSearchable($isSearchable)
223
    {
224 3
        $this->isSearchable = $isSearchable;
225
226
        return $this;
227
    }
228
229
    /**
230 15
     * @param bool $visible
231
     * @return $this
232 15
     */
233
    public function setVisible($visible)
234
    {
235
        $this->visible = $visible;
236
237
        return $this;
238
    }
239
240 13
    /**
241
     * @return ColumnInterface
242 13
     */
243 13
    public function getAppends()
244
    {
245 13
        return $this->append;
246 1
    }
247 1
248
    /**
249 13
     * @param ColumnInterface $append
250
     *
251
     * @return $this
252
     */
253
    public function append(ColumnInterface $append)
254
    {
255
        $this->append = $append;
256
257
        return $this;
258
    }
259 14
260
    /**
261 14
     * @return Model $model
262
     */
263 14
    public function getModel()
264
    {
265
        return $this->model;
266
    }
267
268
    /**
269
     * @param Model $model
270
     *
271 24
     * @return $this
272
     */
273 24
    public function setModel(Model $model)
274 17
    {
275 17
        $this->model = $model;
276
        $append = $this->getAppends();
277 24
278 2
        if ($append instanceof WithModelInterface) {
0 ignored issues
show
introduced by
$append is always a sub-type of SleepingOwl\Admin\Contracts\WithModelInterface.
Loading history...
279
            $append->setModel($model);
280
        }
281 22
282 22
        return $this;
283
    }
284 22
285
    /**
286
     * Set column header label.
287
     *
288
     * @param string $title
289
     *
290 4
     * @return $this
291
     */
292 4
    public function setLabel($title)
293
    {
294
        $this->getHeader()->setTitle($title);
295
296
        return $this;
297
    }
298
299 22
    /**
300
     * @param OrderByClauseInterface|bool|string|\Closure $orderable
301 22
     * @deprecated
302
     * @return $this
303
     */
304
    public function setOrderable($orderable)
305
    {
306
        if ($orderable instanceof \Closure || is_string($orderable)) {
307
            $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

307
            $orderable = new OrderByClause(/** @scrutinizer ignore-type */ $orderable);
Loading history...
308
        }
309
310 1
        if ($orderable !== false && ! $orderable instanceof OrderByClauseInterface) {
311
            throw new \InvalidArgumentException('Argument must be instance of SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface interface');
312 1
        }
313
314
        $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...
315
        $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

315
        $this->getHeader()->/** @scrutinizer ignore-call */ setOrderable($this->isOrderable());
Loading history...
316 1
317
        return $this;
318 1
    }
319
320
    /**
321
     * @return OrderByClauseInterface
322
     */
323
    public function getOrderByClause()
324
    {
325
        return $this->orderByClause;
326 5
    }
327
328
    /**
329 5
     * Check if column is orderable.
330 5
     * @return bool
331 5
     */
332 5
    public function isOrderable()
333
    {
334
        return $this->orderByClause instanceof OrderByClauseInterface;
335
    }
336
337
    /**
338
     * Check if column is visible.
339
     * @return bool
340
     */
341
    public function isVisible()
342
    {
343
        return $this->visible;
344
    }
345
346
    /**
347
     * Check if column is Searchable.
348
     * @return bool
349
     */
350
    public function isSearchable()
351
    {
352
        return $this->isSearchable;
353
    }
354
355
    /**
356
     * @param Builder $query
357
     * @param string $direction
358
     * @deprecated
359
     * @return $this
360
     */
361
    public function orderBy(Builder $query, $direction)
362
    {
363
        if (! $this->isOrderable()) {
364
            throw new \InvalidArgumentException('Argument must be instance of SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface interface');
365
        }
366
367
        $this->orderByClause->modifyQuery($query, $direction);
368
369
        return $this;
370
    }
371
372
    /**
373
     * Get the instance as an array.
374
     *
375
     * @return array
376
     */
377
    public function toArray()
378
    {
379
        return [
380
            'attributes' => $this->htmlAttributesToString(),
381
            'model'      => $this->getModel(),
382
            'append'     => $this->getAppends(),
383
        ];
384
    }
385
386
    /**
387
     * Get related model configuration.
388
     * @return ModelConfigurationInterface
389
     */
390
    protected function getModelConfiguration()
391
    {
392
        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

392
        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...
393
            $this->getModel()
394
        );
395
    }
396
}
397