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 — bs4 (#1107)
by butschster
14:29 queued 08:08
created

DependentSelect   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 212
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 57
c 0
b 0
f 0
dl 0
loc 212
rs 10
wmc 19

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataDepends() 0 3 1
A __construct() 0 6 1
A setAjaxParameters() 0 5 1
A setInitializable() 0 5 1
A setDataDepends() 0 5 2
A getDependValue() 0 3 1
A registerRoutes() 0 8 2
A getDataUrl() 0 6 2
A toArray() 0 28 3
A getLanguage() 0 3 1
A hasDependKey() 0 3 1
A isInitializable() 0 3 1
A setDataUrl() 0 5 1
A setLanguage() 0 5 1
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Element;
4
5
use AdminSection;
0 ignored issues
show
Bug introduced by
The type AdminSection 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...
6
use Illuminate\Support\Arr;
7
use Illuminate\Routing\Router;
8
use SleepingOwl\Admin\Contracts\WithRoutesInterface;
9
10
class DependentSelect extends Select implements WithRoutesInterface
11
{
12
    /**
13
     * @var mixed
14
     */
15
    protected $defaultValue = 0;
16
17
    /**
18
     * @var string|null
19
     */
20
    protected $language;
21
22
    /**
23
     * @var bool
24
     */
25
    protected $initializable = true;
26
27
    /**
28
     * @param Router $router
29
     */
30
    public static function registerRoutes(Router $router)
31
    {
32
        $routeName = 'admin.form.element.dependent-select';
33
34
        if (! $router->has($routeName)) {
35
            $router->post('{adminModel}/dependent-select/{field}/{id?}', [
36
                'as' => $routeName,
37
                'uses' => '\SleepingOwl\Admin\Http\Controllers\FormElementController@dependentSelect',
0 ignored issues
show
Bug introduced by
The controller App\Http\Controllers\\Sl...s\FormElementController does not seem to exist.

If there is a route defined but the controller class cannot be found there are two options: 1. the controller class needs to be implemented or 2. the route is outdated and can be removed.

If ?FooController? was found and ?BarController? is missing for the following example, either the controller should be implemented or the route should be removed:

$app->group(['as' => 'foo', 'prefix' => 'foo', 'namespace' => 'Foo'], function($app) {
    $app->group(['as' => 'foo', 'prefix' => 'foo'], function($app) {
        $app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'FooController@getFoo']);
        $app->get('/all/{from}/{to}', ['as' => 'all', 'uses' => 'BarController@getBar']);
    });
});
Loading history...
38
            ]);
39
        }
40
    }
41
42
    /**
43
     * @var string
44
     */
45
    protected $dataUrl = '';
46
47
    /**
48
     * @var array
49
     */
50
    protected $dataDepends = [];
51
52
    /**
53
     * @var array
54
     */
55
    protected $params;
56
57
    /**
58
     * @var string
59
     */
60
    protected $view = 'form.element.dependentselect';
61
62
    /**
63
     * DependentSelect constructor.
64
     * @param $path
65
     * @param null $label
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $label is correct as it would always require null to be passed?
Loading history...
66
     * @param array $depends
67
     * @throws \SleepingOwl\Admin\Exceptions\Form\Element\SelectException
68
     * @throws \SleepingOwl\Admin\Exceptions\Form\FormElementException
69
     */
70
    public function __construct($path, $label = null, array $depends = [])
71
    {
72
        parent::__construct($path, $label, []);
73
74
        $this->setLanguage(config('app.locale'));
75
        $this->setDataDepends($depends);
76
    }
77
78
    /**
79
     * @return string|null
80
     */
81
    public function getLanguage()
82
    {
83
        return $this->language;
84
    }
85
86
    /**
87
     * @param $language
88
     * @return $this
89
     */
90
    public function setLanguage($language)
91
    {
92
        $this->language = $language;
93
94
        return $this;
95
    }
96
97
    /**
98
     * @return bool
99
     */
100
    public function isInitializable()
101
    {
102
        return $this->initializable;
103
    }
104
105
    /**
106
     * @param bool $initializable
107
     */
108
    public function setInitializable($initializable)
109
    {
110
        $this->initializable = $initializable;
111
112
        return $this;
113
    }
114
115
    /**
116
     * @param string $key
117
     *
118
     * @return bool
119
     */
120
    public function hasDependKey($key)
121
    {
122
        return Arr::has($this->params, $key);
123
    }
124
125
    /**
126
     * @param string $key
127
     *
128
     * @return mixed
129
     */
130
    public function getDependValue($key)
131
    {
132
        return Arr::get($this->params, $key, $this->getModel()->getAttribute($key));
133
    }
134
135
    /**
136
     * @return string
137
     */
138
    public function getDataUrl()
139
    {
140
        return $this->dataUrl ?: route('admin.form.element.dependent-select', [
141
            'adminModel' => AdminSection::getModel($this->model)->getAlias(),
142
            'field' => $this->getName(),
143
            'id' => $this->model->getKey(),
144
        ]);
145
    }
146
147
    /**
148
     * @param string $dataUrl
149
     *
150
     * @return $this
151
     */
152
    public function setDataUrl($dataUrl)
153
    {
154
        $this->dataUrl = $dataUrl;
155
156
        return $this;
157
    }
158
159
    /**
160
     * @return string Json
161
     */
162
    public function getDataDepends()
163
    {
164
        return json_encode($this->dataDepends);
165
    }
166
167
    /**
168
     * @param array|string $depends
169
     *
170
     * @return $this
171
     */
172
    public function setDataDepends($depends)
173
    {
174
        $this->dataDepends = is_array($depends) ? $depends : func_get_args();
175
176
        return $this;
177
    }
178
179
    /**
180
     * @param array $params
181
     *
182
     * @return $this
183
     */
184
    public function setAjaxParameters(array $params)
185
    {
186
        $this->params = $params;
187
188
        return $this;
189
    }
190
191
    /**
192
     * @return array
193
     */
194
    public function toArray()
195
    {
196
        $this->setHtmlAttributes([
197
            'id' => $this->getId(),
198
            'data-select-type' => 'single',
199
            'data-url' => $this->getDataUrl(),
200
            'data-depends' => $this->getDataDepends(),
201
            'data-language' => $this->getLanguage(),
202
            'data-initialize' => $this->isInitializable() ? 'true' : 'false',
203
            'class' => 'form-control input-select input-select-dependent',
204
        ]);
205
206
        if ($this->isReadonly()) {
207
            $this->setHtmlAttribute('disabled', 'disabled');
208
        }
209
210
        return [
211
            'id' => $this->getId(),
212
            'name' => $this->getName(),
213
            'path' => $this->getPath(),
214
            'label' => $this->getLabel(),
215
            'readonly' => $this->isReadonly(),
216
            'visibled' => $this->isVisible(),
217
            'options' => $this->getOptions(),
218
            'value' => $this->getValueFromModel(),
219
            'helpText' => $this->getHelpText(),
220
            'required' => in_array('required', $this->validationRules),
221
            'attributes' => $this->getHtmlAttributes(),
222
        ];
223
    }
224
}
225