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.

Issues (389)

Branch: master

src/Display/Extension/Columns.php (8 issues)

1
<?php
2
3
namespace SleepingOwl\Admin\Display\Extension;
4
5
use Illuminate\Contracts\Pagination\Paginator;
6
use Illuminate\Contracts\Support\Renderable;
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\Collection;
9
use SleepingOwl\Admin\Contracts\Display\ColumnInterface;
10
use SleepingOwl\Admin\Contracts\Display\ColumnMetaInterface;
11
use SleepingOwl\Admin\Contracts\Initializable;
12
use SleepingOwl\Admin\Display\Column\Control;
13
14
class Columns extends Extension implements Initializable, Renderable
15
{
16
    use \SleepingOwl\Admin\Traits\Renderable;
17
18
    /**
19
     * @var ColumnInterface[]|Collection
20
     */
21
    protected $columns;
22
23
    /**
24
     * @var bool
25
     */
26
    protected $controlActive = true;
27
28
    /**
29
     * @var string
30
     */
31
    protected $view = 'display.extensions.columns';
32
33
    /**
34
     * @var bool
35
     */
36
    protected $initialize = false;
37
38
    /**
39
     * @var Control
40
     */
41
    protected $controlColumn;
42
43
    public function __construct()
44
    {
45
        $this->columns = new Collection();
46
47
        $this->setControlColumn(app('sleeping_owl.table.column')->control());
0 ignored issues
show
The method control() 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

47
        $this->setControlColumn(app('sleeping_owl.table.column')->/** @scrutinizer ignore-call */ control());

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...
48
    }
49
50
    /**
51
     * @param ColumnInterface $controlColumn
52
     *
53
     * @return $this
54
     */
55
    public function setControlColumn(ColumnInterface $controlColumn)
56
    {
57
        $this->controlColumn = $controlColumn;
0 ignored issues
show
Documentation Bug introduced by
$controlColumn is of type SleepingOwl\Admin\Contra...Display\ColumnInterface, but the property $controlColumn was declared to be of type SleepingOwl\Admin\Display\Column\Control. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof 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 given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
58
59
        return $this;
60
    }
61
62
    /**
63
     * @return Control
64
     */
65
    public function getControlColumn()
66
    {
67
        return $this->controlColumn;
68
    }
69
70
    /**
71
     * @return bool
72
     */
73
    public function isControlActive()
74
    {
75
        return $this->controlActive;
76
    }
77
78
    /**
79
     * @return $this
80
     */
81
    public function enableControls()
82
    {
83
        $this->controlActive = true;
84
85
        return $this;
86
    }
87
88
    /**
89
     * @return $this
90
     */
91
    public function disableControls()
92
    {
93
        $this->controlActive = false;
94
95
        if ($this->isInitialize()) {
96
            $this->columns = $this->columns->filter(function ($column) {
97
                $class = get_class($this->getControlColumn());
98
99
                return ! ($column instanceof $class);
100
            });
101
        }
102
103
        return $this;
104
    }
105
106
    /**
107
     * @return Collection|\SleepingOwl\Admin\Contracts\Display\ColumnInterface[]
108
     */
109
    public function all()
110
    {
111
        return $this->columns;
112
    }
113
114
    /**
115
     * @param $columns
116
     *
117
     * @return \SleepingOwl\Admin\Contracts\Display\DisplayInterface
118
     */
119
    public function set($columns)
120
    {
121
        if (! is_array($columns)) {
122
            $columns = func_get_args();
123
        }
124
125
        foreach ($columns as $column) {
126
            $this->push($column);
127
        }
128
129
        return $this->getDisplay();
130
    }
131
132
    /**
133
     * @param ColumnInterface $column
134
     *
135
     * @return $this
136
     */
137
    public function push(ColumnInterface $column)
138
    {
139
        $this->columns->push($column);
140
141
        return $this;
142
    }
143
144
    /**
145
     * @return bool
146
     */
147
    public function isInitialize()
148
    {
149
        return $this->initialize;
150
    }
151
152
    /**
153
     * Get the instance as an array.
154
     *
155
     * @return array
156
     */
157
    public function toArray()
158
    {
159
        return [
160
            'columns' => $this->all(),
161
            'attributes' => $this->getDisplay()->htmlAttributesToString(),
0 ignored issues
show
The method htmlAttributesToString() does not exist on SleepingOwl\Admin\Contra...isplay\DisplayInterface. It seems like you code against a sub-type of said class. However, the method does not exist in SleepingOwl\Admin\Display\DisplayTabbed. Are you sure you never get one of those? ( Ignorable by Annotation )

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

161
            'attributes' => $this->getDisplay()->/** @scrutinizer ignore-call */ htmlAttributesToString(),
Loading history...
162
        ];
163
    }
164
165
    public function initialize()
166
    {
167
        $this->all()->each(function (ColumnInterface $column) {
168
            $column->initialize();
169
        });
170
171
        if ($this->isControlActive()) {
172
            $this->push($this->getControlColumn());
173
        }
174
175
        $this->initialize = true;
176
    }
177
178
    /**
179
     * Get the evaluated contents of the object.
180
     *
181
     * @return string
182
     */
183
    public function render()
184
    {
185
        $params = $this->toArray();
186
        $params['collection'] = $this->getDisplay()->getCollection();
0 ignored issues
show
The method getCollection() does not exist on SleepingOwl\Admin\Contra...isplay\DisplayInterface. It seems like you code against a sub-type of SleepingOwl\Admin\Contra...isplay\DisplayInterface such as SleepingOwl\Admin\Display\Display. ( Ignorable by Annotation )

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

186
        $params['collection'] = $this->getDisplay()->/** @scrutinizer ignore-call */ getCollection();
Loading history...
187
        $params['pagination'] = null;
188
189
        if ($params['collection'] instanceof Paginator) {
190
            if (class_exists('Illuminate\Pagination\BootstrapThreePresenter')) {
191
                $params['pagination'] = (new \Illuminate\Pagination\BootstrapThreePresenter($params['collection']))->render();
0 ignored issues
show
The type Illuminate\Pagination\BootstrapThreePresenter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
192
            } else {
193
                $params['pagination'] = $params['collection']->render();
194
            }
195
        }
196
197
        return app('sleeping_owl.template')->view($this->getView(), $params)->render();
0 ignored issues
show
The method view() 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

197
        return app('sleeping_owl.template')->/** @scrutinizer ignore-call */ view($this->getView(), $params)->render();

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...
198
    }
199
200
    /**
201
     * @param \Illuminate\Database\Eloquent\Builder $query
202
     */
203
    public function modifyQuery(\Illuminate\Database\Eloquent\Builder $query)
204
    {
205
        $orders = app('request')->get('order', []);
206
207
        $columns = $this->all();
208
209
        if (! is_int(key($orders))) {
210
            $orders = [$orders];
211
        }
212
213
        $_model = $query->getModel();
214
215
        foreach ($orders as $order) {
216
            $columnIndex = Arr::get($order, 'column');
217
            $direction = Arr::get($order, 'dir', 'asc');
218
219
            if (! $columnIndex && $columnIndex !== '0') {
220
                continue;
221
            }
222
223
            $column = $columns->get($columnIndex);
224
225
            if ($column instanceof ColumnInterface && $column->isOrderable()) {
226
                if ($column instanceof ColumnInterface) {
227
                    if (($metaInstance = $column->getMetaData()) instanceof ColumnMetaInterface) {
0 ignored issues
show
The method getMetaData() does not exist on SleepingOwl\Admin\Contra...Display\ColumnInterface. It seems like you code against a sub-type of said class. However, the method does not exist in SleepingOwl\Admin\Contra...ColumnEditableInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

227
                    if (($metaInstance = $column->/** @scrutinizer ignore-call */ getMetaData()) instanceof ColumnMetaInterface) {
Loading history...
228
                        if (method_exists($metaInstance, 'onOrderBy')) {
229
                            $metaInstance->onOrderBy($column, $query, $direction);
230
                            continue;
231
                        }
232
                    }
233
234
                    if (is_callable($callback = $column->getOrderCallback())) {
0 ignored issues
show
The method getOrderCallback() does not exist on SleepingOwl\Admin\Contra...Display\ColumnInterface. It seems like you code against a sub-type of said class. However, the method does not exist in SleepingOwl\Admin\Contra...ColumnEditableInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

234
                    if (is_callable($callback = $column->/** @scrutinizer ignore-call */ getOrderCallback())) {
Loading history...
235
                        $callback($column, $query, $direction);
236
                        continue;
237
                    }
238
                }
239
240
                if ($_model->getAttribute($column->getName())) {
241
                    continue;
242
                }
243
244
                $column->orderBy($query, $direction);
245
            }
246
        }
247
    }
248
}
249