Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
10 | class Select extends Field |
||
11 | { |
||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | protected static $css = [ |
||
16 | '/vendor/laravel-admin/AdminLTE/plugins/select2/select2.min.css', |
||
17 | ]; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected static $js = [ |
||
23 | '/vendor/laravel-admin/AdminLTE/plugins/select2/select2.full.min.js', |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $groups = []; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $config = []; |
||
35 | |||
36 | /** |
||
37 | * Set options. |
||
38 | * |
||
39 | * @param array|callable|string $options |
||
40 | * |
||
41 | * @return $this|mixed |
||
42 | */ |
||
43 | public function options($options = []) |
||
67 | |||
68 | /** |
||
69 | * @param array $groups |
||
70 | */ |
||
71 | |||
72 | /** |
||
73 | * Set option groups. |
||
74 | * |
||
75 | * eg: $group = [ |
||
76 | * [ |
||
77 | * 'label' => 'xxxx', |
||
78 | * 'options' => [ |
||
79 | * 1 => 'foo', |
||
80 | * 2 => 'bar', |
||
81 | * ... |
||
82 | * ], |
||
83 | * ... |
||
84 | * ] |
||
85 | * |
||
86 | * @param array $groups |
||
87 | * |
||
88 | * @return $this |
||
89 | */ |
||
90 | public function groups(array $groups) |
||
96 | |||
97 | /** |
||
98 | * Load options for other select on change. |
||
99 | * |
||
100 | * @param string $field |
||
101 | * @param string $sourceUrl |
||
102 | * @param string $idField |
||
103 | * @param string $textField |
||
104 | * |
||
105 | * @return $this |
||
106 | */ |
||
107 | public function load($field, $sourceUrl, $idField = 'id', $textField = 'text') |
||
137 | |||
138 | /** |
||
139 | * Load options for other selects on change. |
||
140 | * |
||
141 | * @param string $fields |
||
142 | * @param string $sourceUrls |
||
143 | * @param string $idField |
||
144 | * @param string $textField |
||
145 | * |
||
146 | * @return $this |
||
147 | */ |
||
148 | public function loads($fields = [], $sourceUrls = [], $idField = 'id', $textField = 'text') |
||
189 | |||
190 | /** |
||
191 | * Load options from current selected resource(s). |
||
192 | * |
||
193 | * @param Illuminate\Database\Eloquent\Model $model |
||
194 | * @param string $textField |
||
195 | * @param string $idField |
||
196 | * |
||
197 | * @return $this |
||
198 | */ |
||
199 | protected function selected($model, $textField = 'name', $idField = 'id') |
||
235 | |||
236 | /** |
||
237 | * Load options from remote. |
||
238 | * |
||
239 | * @param string $url |
||
240 | * @param array $parameters |
||
241 | * @param array $options |
||
242 | * |
||
243 | * @return $this |
||
244 | */ |
||
245 | View Code Duplication | protected function loadRemoteOptions($url, $parameters = [], $options = []) |
|
263 | |||
264 | /** |
||
265 | * Load options from ajax results. |
||
266 | * |
||
267 | * @param string $url |
||
268 | * @param $idField |
||
269 | * @param $textField |
||
270 | * |
||
271 | * @return $this |
||
272 | */ |
||
273 | public function ajax($url, $idField = 'id', $textField = 'text') |
||
323 | |||
324 | /** |
||
325 | * Set config for select2. |
||
326 | * |
||
327 | * all configurations see https://select2.org/configuration/options-api |
||
328 | * |
||
329 | * @param string $key |
||
330 | * @param mixed $val |
||
331 | * |
||
332 | * @return $this |
||
333 | */ |
||
334 | public function config($key, $val) |
||
340 | |||
341 | /** |
||
342 | * {@inheritdoc} |
||
343 | */ |
||
344 | public function render() |
||
374 | } |
||
375 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: