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
Pull Request — master (#688)
by
unknown
18:52
created

TableColumn   A

Complexity

Total Complexity 33

Size/Duplication

Total Lines 329
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 6

Test Coverage

Coverage 68.6%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 33
lcom 4
cbo 6
dl 0
loc 329
ccs 59
cts 86
cp 0.686
rs 9.3999
c 1
b 0
f 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A initialize() 0 4 1
A setMetaData() 0 6 1
A getMetaData() 0 6 2
A setOrderCallback() 0 6 1
A setSearchCallback() 0 6 1
A setFilterCallback() 0 6 1
A getOrderCallback() 0 4 1
A getSearchCallback() 0 4 1
A getFilterCallback() 0 4 1
A getHeader() 0 4 1
A getWidth() 0 4 1
A setWidth() 0 10 2
A getAppends() 0 4 1
A append() 0 6 1
A getModel() 0 4 1
A setModel() 0 11 2
A setLabel() 0 6 1
B setOrderable() 0 15 5
A getOrderByClause() 0 4 1
A isOrderable() 0 4 1
A orderBy() 0 10 2
A toArray() 0 8 1
A getModelConfiguration() 0 6 1
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;
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
     * TableColumn constructor.
75
     *
76
     * @param string|null $label
77
     */
78 45
    public function __construct($label = null)
79
    {
80 45
        $this->header = app(TableHeaderColumnInterface::class);
81
82 45
        if (! is_null($label)) {
83 11
            $this->setLabel($label);
84 11
        }
85
86 45
        $this->initializePackage();
87 45
    }
88
89
    /**
90
     * Initialize column.
91
     */
92 2
    public function initialize()
93
    {
94 2
        $this->includePackage();
95 2
    }
96
97
    /**
98
     * @param $columnMetaClass
99
     * @return $this
100
     */
101
    public function setMetaData($columnMetaClass)
102
    {
103
        $this->columMetaClass = $columnMetaClass;
104
105
        return $this;
106
    }
107
108
    /**
109
     * @return mixed
110
     */
111
    public function getMetaData()
112
    {
113
        return $this->columMetaClass
114
            ? app()->make($this->columMetaClass)
115
            : false;
116
    }
117
118
    /**
119
     * @param \Closure $callable
120
     * @return $this
121
     */
122
    public function setOrderCallback(\Closure $callable)
123
    {
124
        $this->orderCallback = $callable;
125
126
        return $this->setOrderable($callable);
0 ignored issues
show
Deprecated Code introduced by
The method SleepingOwl\Admin\Displa...eColumn::setOrderable() has been deprecated.

This method has been deprecated.

Loading history...
127
    }
128
129
    /**
130
     * @param \Closure $callable
131
     * @return $this
132
     */
133
    public function setSearchCallback(\Closure $callable)
134
    {
135
        $this->searchCallback = $callable;
136
137
        return $this;
138
    }
139
140
    /**
141
     * @param \Closure $callable
142
     * @return $this
143
     */
144
    public function setFilterCallback(\Closure $callable)
145
    {
146
        $this->filterCallback = $callable;
147
148
        return $this;
149
    }
150
151
    /**
152
     * @return \Closure
153
     */
154
    public function getOrderCallback()
155
    {
156
        return $this->orderCallback;
157
    }
158
159
    /**
160
     * @return \Closure
161
     */
162
    public function getSearchCallback()
163
    {
164
        return $this->searchCallback;
165
    }
166
167
    /**
168
     * @return \Closure
169
     */
170
    public function getFilterCallback()
171
    {
172
        return $this->filterCallback;
173
    }
174
175
    /**
176
     * @return TableHeaderColumnInterface
177
     */
178 24
    public function getHeader()
179
    {
180 24
        return $this->header;
181
    }
182
183
    /**
184
     * @return int
185
     */
186 1
    public function getWidth()
187
    {
188 1
        return $this->width;
189
    }
190
191
    /**
192
     * @param int|string $width
193
     *
194
     * @return $this
195
     */
196 1
    public function setWidth($width)
197
    {
198 1
        if (is_int($width)) {
199 1
            $width = $width.'px';
200 1
        }
201
202 1
        $this->width = $width;
203
204 1
        return $this;
205
    }
206
207
    /**
208
     * @return ColumnInterface
209
     */
210 16
    public function getAppends()
211
    {
212 16
        return $this->append;
213
    }
214
215
    /**
216
     * @param ColumnInterface $append
217
     *
218
     * @return $this
219
     */
220 3
    public function append(ColumnInterface $append)
221
    {
222 3
        $this->append = $append;
223
224 3
        return $this;
225
    }
226
227
    /**
228
     * @return Model $model
229
     */
230 15
    public function getModel()
231
    {
232 15
        return $this->model;
233
    }
234
235
    /**
236
     * @param Model $model
237
     *
238
     * @return $this
239
     */
240 13
    public function setModel(Model $model)
241
    {
242 13
        $this->model = $model;
243 13
        $append = $this->getAppends();
244
245 13
        if ($append instanceof WithModelInterface) {
246 1
            $append->setModel($model);
247 1
        }
248
249 13
        return $this;
250
    }
251
252
    /**
253
     * Set column header label.
254
     *
255
     * @param string $title
256
     *
257
     * @return $this
258
     */
259 14
    public function setLabel($title)
260
    {
261 14
        $this->getHeader()->setTitle($title);
262
263 14
        return $this;
264
    }
265
266
    /**
267
     * @param OrderByClauseInterface|bool|string|\Closure $orderable
268
     * @deprecated
269
     * @return $this
270
     */
271 24
    public function setOrderable($orderable)
272
    {
273 24
        if ($orderable instanceof \Closure || is_string($orderable)) {
274 17
            $orderable = new OrderByClause($orderable);
0 ignored issues
show
Bug introduced by
It seems like $orderable defined by new \SleepingOwl\Admin\D...derByClause($orderable) on line 274 can also be of type object<Closure>; however, SleepingOwl\Admin\Displa...ByClause::__construct() does only seem to accept string|object<Mockery\Matcher\Closure>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
275 17
        }
276
277 24
        if ($orderable !== false && ! $orderable instanceof OrderByClauseInterface) {
278 2
            throw new \InvalidArgumentException('Argument must be instance of SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface interface');
279
        }
280
281 22
        $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 object<SleepingOwl\Admin...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...
282 22
        $this->getHeader()->setOrderable($this->isOrderable());
283
284 22
        return $this;
285
    }
286
287
    /**
288
     * @return OrderByClauseInterface
289
     */
290 4
    public function getOrderByClause()
291
    {
292 4
        return $this->orderByClause;
293
    }
294
295
    /**
296
     * Check if column is orderable.
297
     * @return bool
298
     */
299 22
    public function isOrderable()
300
    {
301 22
        return $this->orderByClause instanceof OrderByClauseInterface;
302
    }
303
304
    /**
305
     * @param Builder $query
306
     * @param string $direction
307
     * @deprecated
308
     * @return $this
309
     */
310 1
    public function orderBy(Builder $query, $direction)
311
    {
312 1
        if (! $this->isOrderable()) {
313
            throw new \InvalidArgumentException('Argument must be instance of SleepingOwl\Admin\Contracts\Display\OrderByClauseInterface interface');
314
        }
315
316 1
        $this->orderByClause->modifyQuery($query, $direction);
317
318 1
        return $this;
319
    }
320
321
    /**
322
     * Get the instance as an array.
323
     *
324
     * @return array
325
     */
326 5
    public function toArray()
327
    {
328
        return [
329 5
            'attributes' => $this->htmlAttributesToString(),
330 5
            'model'      => $this->getModel(),
331 5
            'append'     => $this->getAppends(),
332 5
        ];
333
    }
334
335
    /**
336
     * Get related model configuration.
337
     * @return ModelConfigurationInterface
338
     */
339
    protected function getModelConfiguration()
340
    {
341
        return app('sleeping_owl')->getModel(
342
            $this->getModel()
343
        );
344
    }
345
}
346