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

Columns::getControlColumn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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

45
        $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...
46
    }
47
48
    /**
49
     * @param ColumnInterface $controlColumn
50
     *
51
     * @return $this
52
     */
53
    public function setControlColumn(ColumnInterface $controlColumn)
54
    {
55
        $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...
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return Control
62
     */
63
    public function getControlColumn()
64
    {
65
        return $this->controlColumn;
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function isControlActive()
72
    {
73
        return $this->controlActive;
74
    }
75
76
    /**
77
     * @return $this
78
     */
79
    public function enableControls()
80
    {
81
        $this->controlActive = true;
82
83
        return $this;
84
    }
85
86
    /**
87
     * @return $this
88
     */
89
    public function disableControls()
90
    {
91
        $this->controlActive = false;
92
93
        if ($this->isInitialize()) {
94
            $this->columns = $this->columns->filter(function ($column) {
95
                $class = get_class($this->getControlColumn());
96
97
                return ! ($column instanceof $class);
98
            });
99
        }
100
101
        return $this;
102
    }
103
104
    /**
105
     * @return Collection|\SleepingOwl\Admin\Contracts\Display\ColumnInterface[]
106
     */
107
    public function all()
108
    {
109
        return $this->columns;
110
    }
111
112
    /**
113
     * @param $columns
114
     *
115
     * @return \SleepingOwl\Admin\Contracts\Display\DisplayInterface
116
     */
117
    public function set($columns)
118
    {
119
        if (! is_array($columns)) {
120
            $columns = func_get_args();
121
        }
122
123
        foreach ($columns as $column) {
124
            $this->push($column);
125
        }
126
127
        return $this->getDisplay();
128
    }
129
130
    /**
131
     * @param ColumnInterface $column
132
     *
133
     * @return $this
134
     */
135
    public function push(ColumnInterface $column)
136
    {
137
        $this->columns->push($column);
138
139
        return $this;
140
    }
141
142
    /**
143
     * @return bool
144
     */
145
    public function isInitialize()
146
    {
147
        return $this->initialize;
148
    }
149
150
    /**
151
     * Get the instance as an array.
152
     *
153
     * @return array
154
     */
155
    public function toArray()
156
    {
157
        return [
158
            'columns' => $this->all(),
159
            'attributes' => $this->getDisplay()->htmlAttributesToString(),
0 ignored issues
show
Bug introduced by
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

159
            'attributes' => $this->getDisplay()->/** @scrutinizer ignore-call */ htmlAttributesToString(),
Loading history...
160
        ];
161
    }
162
163
    public function initialize()
164
    {
165
        $this->all()->each(function (ColumnInterface $column) {
166
            $column->initialize();
167
        });
168
169
        if ($this->isControlActive()) {
170
            $this->push($this->getControlColumn());
171
        }
172
173
        $this->initialize = true;
174
    }
175
176
    /**
177
     * Get the evaluated contents of the object.
178
     *
179
     * @return string
180
     */
181
    public function render()
182
    {
183
        $params = $this->toArray();
184
        $params['collection'] = $this->getDisplay()->getCollection();
0 ignored issues
show
Bug introduced by
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

184
        $params['collection'] = $this->getDisplay()->/** @scrutinizer ignore-call */ getCollection();
Loading history...
185
        $params['pagination'] = null;
186
187
        if ($params['collection'] instanceof \Illuminate\Contracts\Pagination\Paginator) {
188
            if (class_exists('Illuminate\Pagination\BootstrapThreePresenter')) {
189
                $params['pagination'] = (new \Illuminate\Pagination\BootstrapThreePresenter($params['collection']))->render();
0 ignored issues
show
Bug introduced by
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...
190
            } else {
191
                $params['pagination'] = $params['collection']->render();
192
            }
193
        }
194
195
        return app('sleeping_owl.template')->view($this->getView(), $params)->render();
0 ignored issues
show
Bug introduced by
The method view() 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

195
        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...
196
    }
197
198
    /**
199
     * @param \Illuminate\Database\Eloquent\Builder $query
200
     */
201
    public function modifyQuery(\Illuminate\Database\Eloquent\Builder $query)
202
    {
203
        $orders = \Request::input('order', []);
204
205
        $columns = $this->all();
206
207
        if (! is_int(key($orders))) {
208
            $orders = [$orders];
209
        }
210
211
        foreach ($orders as $order) {
212
            $columnIndex = array_get($order, 'column');
213
            $direction = array_get($order, 'dir', 'asc');
214
215
            if (! $columnIndex && $columnIndex !== '0') {
216
                continue;
217
            }
218
219
            $column = $columns->get($columnIndex);
220
221
            if ($column instanceof ColumnInterface && $column->isOrderable()) {
222
                if ($column instanceof ColumnInterface) {
223
                    if (($metaInstance = $column->getMetaData()) instanceof ColumnMetaInterface) {
0 ignored issues
show
Bug introduced by
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

223
                    if (($metaInstance = $column->/** @scrutinizer ignore-call */ getMetaData()) instanceof ColumnMetaInterface) {
Loading history...
224
                        if (method_exists($metaInstance, 'onOrderBy')) {
225
                            $metaInstance->onOrderBy($column, $query, $direction);
226
                            continue;
227
                        }
228
                    }
229
230
                    if (is_callable($callback = $column->getOrderCallback())) {
0 ignored issues
show
Bug introduced by
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

230
                    if (is_callable($callback = $column->/** @scrutinizer ignore-call */ getOrderCallback())) {
Loading history...
231
                        $callback($column, $query, $direction);
232
                        continue;
233
                    }
234
                }
235
                $column->orderBy($query, $direction);
236
            }
237
        }
238
    }
239
}
240