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.
Passed
Push — master ( b2510c...ee0bb8 )
by
unknown
12:46
created

BaseColumnFilter::apply()   C

Complexity

Conditions 8
Paths 15

Size

Total Lines 44
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 10.1247

Importance

Changes 0
Metric Value
dl 0
loc 44
c 0
b 0
f 0
cc 8
eloc 24
nc 15
nop 4
ccs 19
cts 28
cp 0.6786
crap 10.1247
rs 5.3846
1
<?php
2
3
namespace SleepingOwl\Admin\Display\Column\Filter;
4
5
use SleepingOwl\Admin\Traits\Assets;
6
use Illuminate\Database\Eloquent\Builder;
7
use KodiComponents\Support\HtmlAttributes;
8
use Illuminate\Contracts\Support\Arrayable;
9
use Illuminate\Contracts\Support\Renderable;
10
use SleepingOwl\Admin\Traits\SqlQueryOperators;
11
use SleepingOwl\Admin\Contracts\Display\ColumnMetaInterface;
12
use SleepingOwl\Admin\Contracts\Display\NamedColumnInterface;
13
use SleepingOwl\Admin\Contracts\Display\Extension\ColumnFilterInterface;
14
15
abstract class BaseColumnFilter implements Renderable, ColumnFilterInterface, Arrayable
16
{
17
    use SqlQueryOperators, HtmlAttributes, Assets, \SleepingOwl\Admin\Traits\Renderable;
18
19
    /**
20
     * @var \Closure|null
21
     */
22
    protected $callback;
23
24
    /**
25
     * @var string|null
26
     */
27
    protected $columnName;
28
29 62
    public function __construct()
30
    {
31 62
        $this->initializePackage();
32 62
    }
33
34
    /**
35
     * Initialize column filter.
36
     */
37 3
    public function initialize()
38
    {
39 3
        $this->includePackage();
40 3
    }
41
42
    /**
43
     * @return null|string
44
     */
45 40
    public function getColumnName()
46
    {
47 40
        return $this->columnName;
48
    }
49
50
    /**
51
     * @param null|string $name
52
     *
53
     * @return $this
54
     */
55
    public function setColumnName($name)
56
    {
57
        $this->columnName = $name;
58
59
        return $this;
60
    }
61
62
    /**
63
     * @param mixed $value
64
     *
65
     * @return mixed
66
     */
67 40
    public function parseValue($value)
68
    {
69 40
        return $value;
70
    }
71
72
    /**
73
     * @deprecated
74
     * @return \Closure|null
75
     */
76 40
    public function getCallback()
77
    {
78 40
        return $this->callback;
79
    }
80
81
    /**
82
     * @param \Closure $callback
83
     * @deprecated
84
     * @return $this
85
     */
86
    public function setCallback(\Closure $callback)
87
    {
88
        $this->callback = $callback;
89
90
        return $this;
91
    }
92
93
    /**
94
     * @param NamedColumnInterface $column
95
     * @param Builder $query
96
     * @param string $queryString
97
     * @param array|string $queryParams
98
     *
99
     * @return void
100
     */
101 40
    public function apply(NamedColumnInterface $column, Builder $query, $queryString, $queryParams)
102
    {
103 40
        $queryString = $this->parseValue($queryString);
104
105 40
        if (($metaInstance = $column->getMetaData()) instanceof ColumnMetaInterface) {
106
            if (method_exists($metaInstance, 'onFilterSearch')) {
107
                $metaInstance->onFilterSearch($column, $query, $queryString, $queryParams);
0 ignored issues
show
Bug introduced by
The method onFilterSearch() does not seem to exist on object<SleepingOwl\Admin...ay\ColumnMetaInterface>.

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...
108
109
                return;
110
            }
111
        }
112
113 40
        if (is_callable($callback = $column->getFilterCallback())) {
114
            $callback($column, $query, $queryString, $queryParams);
115
116
            return;
117
        }
118
119 40
        if (is_callable($callback = $this->getCallback())) {
0 ignored issues
show
Deprecated Code introduced by
The method SleepingOwl\Admin\Displa...mnFilter::getCallback() has been deprecated.

This method has been deprecated.

Loading history...
120
            $callback($column, $query, $queryString, $queryParams);
121
122
            return;
123
        }
124
125 40
        if (empty($queryString)) {
126
            return;
127
        }
128
129 40
        if (is_null($name = $this->getColumnName())) {
130 40
            $name = $column->getName();
131 40
        }
132
133 40
        if (strpos($name, '.') !== false) {
134 20
            $parts = explode('.', $name);
135 20
            $fieldName = array_pop($parts);
136 20
            $relationName = implode('.', $parts);
137
138 20
            $query->whereHas($relationName, function ($q) use ($queryString, $fieldName) {
139 20
                $this->buildQuery($q, $fieldName, $queryString);
140 20
            });
141 20
        } else {
142 20
            $this->buildQuery($query, $name, $queryString);
143
        }
144 40
    }
145
146
    /**
147
     * Get the instance as an array.
148
     *
149
     * @return array
150
     */
151
    public function toArray()
152
    {
153
        return [
154
            'attributes'      => $this->htmlAttributesToString(),
155
            'attributesArray' => $this->getHtmlAttributes(),
156
        ];
157
    }
158
}
159