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 — development ( ba4ae1...de4f05 )
by Dave
29:13 queued 22:17
created

DisplayTable::setCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 1
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Display;
4
5
use Request;
6
use Illuminate\Support\Collection;
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Pagination\LengthAwarePaginator;
9
use SleepingOwl\Admin\Display\Extension\Columns;
10
use SleepingOwl\Admin\Display\Extension\ColumnsTotal;
11
use SleepingOwl\Admin\Display\Extension\ColumnFilters;
12
use SleepingOwl\Admin\Contracts\Display\ColumnInterface;
13
use SleepingOwl\Admin\Contracts\Display\Extension\ColumnFilterInterface;
14
15
/**
16
 * Class DisplayTable.
17
 *
18
 * @method Columns getColumns()
19
 * @method $this setColumns(ColumnInterface|ColumnInterface[] $column)
20
 *
21
 * @method ColumnFilters getColumnFilters()
22
 * @method $this setColumnFilters(ColumnFilterInterface $filters = null, ...$filters)
23
 */
24
class DisplayTable extends Display
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $view = 'display.table';
30
31
    /**
32
     * @var array
33
     */
34
    protected $parameters = [];
35
36
    /**
37
     * @var int|null
38
     */
39
    protected $paginate = 25;
40
41
    /**
42
     * @var string
43
     */
44
    protected $pageName = 'page';
45
46
    /**
47
     * @var Collection
48
     */
49
    protected $collection;
50
51
    /**
52
     * @var string|null
53
     */
54
    protected $newEntryButtonText;
55
56
    /**
57
     * Display constructor.
58
     */
59
    public function __construct()
60
    {
61
        parent::__construct();
62
63
        $this->extend('columns', new Columns());
64
        $this->extend('column_filters', new ColumnFilters());
65
        $this->extend('columns_total', new ColumnsTotal());
66
    }
67
68
    /**
69
     * Initialize display.
70
     */
71
    public function initialize()
72
    {
73
        parent::initialize();
74
75
        if ($this->getModelConfiguration()->isRestorableModel()) {
76
            $this->setApply(function (Builder $q) {
77
                return $q->withTrashed();
78
            });
79
        }
80
81
        $this->setHtmlAttribute('class', 'table table-striped');
82
    }
83
84
    /**
85
     * @return array|\Illuminate\Contracts\Translation\Translator|null|string
86
     */
87
    public function getNewEntryButtonText()
88
    {
89
        if (is_null($this->newEntryButtonText)) {
90
            $this->newEntryButtonText = trans('sleeping_owl::lang.table.new-entry');
0 ignored issues
show
Documentation Bug introduced by
It seems like trans('sleeping_owl::lang.table.new-entry') can also be of type array. However, the property $newEntryButtonText is declared as type null|string. 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...
91
        }
92
93
        return $this->newEntryButtonText;
94
    }
95
96
    /**
97
     * @param string $newEntryButtonText
98
     *
99
     * @return $this
100
     */
101
    public function setNewEntryButtonText($newEntryButtonText)
102
    {
103
        $this->newEntryButtonText = $newEntryButtonText;
104
105
        return $this;
106
    }
107
108
    /**
109
     * @return array
110
     */
111
    public function getParameters()
112
    {
113
        return $this->parameters;
114
    }
115
116
    /**
117
     * @param array $parameters
118
     *
119
     * @return $this
120
     */
121
    public function setParameters($parameters)
122
    {
123
        $this->parameters = $parameters;
124
125
        return $this;
126
    }
127
128
    /**
129
     * @param string $key
130
     * @param mixed  $value
131
     *
132
     * @return $this
133
     */
134
    public function setParameter($key, $value)
135
    {
136
        $this->parameters[$key] = $value;
137
138
        return $this;
139
    }
140
141
    /**
142
     * @param int    $perPage
143
     * @param string $pageName
144
     *
145
     * @return $this
146
     */
147
    public function paginate($perPage = 25, $pageName = 'page')
148
    {
149
        $this->paginate = (int) $perPage;
150
        $this->pageName = $pageName;
151
152
        return $this;
153
    }
154
155
    /**
156
     * @return $this
157
     */
158
    public function disablePagination()
159
    {
160
        $this->paginate = 0;
161
162
        return $this;
163
    }
164
165
    /**
166
     * @return bool
167
     */
168
    public function usePagination()
169
    {
170
        return $this->paginate > 0;
171
    }
172
173
    /**
174
     * @return array
175
     * @throws \Exception
176
     */
177
    public function toArray()
178
    {
179
        $model = $this->getModelConfiguration();
180
181
        $params = parent::toArray();
182
183
        $params['creatable'] = $model->isCreatable();
184
        $params['createUrl'] = $model->getCreateUrl($this->getParameters() + Request::all());
185
        $params['collection'] = $this->getCollection();
186
187
        $params['extensions'] = $this->getExtensions()->renderable()->sortByOrder();
188
        $params['newEntryButtonText'] = $this->getNewEntryButtonText();
189
190
        return $params;
191
    }
192
193
    /**
194
     * $collection Collection|LengthAwarePaginator|Builder.
195
     */
196
    public function setCollection($collection)
197
    {
198
        $this->collection = $collection;
199
    }
200
201
    /**
202
     * @return Collection|LengthAwarePaginator|Builder
203
     * @throws \Exception
204
     */
205
    public function getCollection()
206
    {
207
        if (! $this->isInitialized()) {
208
            throw new \Exception('Display is not initialized');
209
        }
210
211
        if (! is_null($this->collection)) {
212
            return $this->collection;
213
        }
214
215
        $query = $this->getRepository()->getQuery();
216
217
        $this->modifyQuery($query);
218
219
        return $this->collection = $this->usePagination()
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->usePagination() ?...eName)) : $query->get() can also be of type Illuminate\Pagination\LengthAwarePaginator. However, the property $collection is declared as type Illuminate\Support\Collection. 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...
220
            ? $query->paginate($this->paginate, ['*'], $this->pageName)->appends(request()->except($this->pageName))
221
            : $query->get();
222
    }
223
224
    /**
225
     * @param \Illuminate\Database\Eloquent\Builder|Builder $query
226
     */
227
    protected function modifyQuery(\Illuminate\Database\Eloquent\Builder $query)
228
    {
229
        $this->extensions->modifyQuery($query);
230
    }
231
}
232