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 |
||
12 | class Select extends Field |
||
13 | { |
||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | protected static $css = [ |
||
18 | '/vendor/laravel-admin/AdminLTE/plugins/select2/select2.min.css', |
||
19 | ]; |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | protected static $js = [ |
||
25 | '/vendor/laravel-admin/AdminLTE/plugins/select2/select2.full.min.js', |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $groups = []; |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $config = []; |
||
37 | |||
38 | /** |
||
39 | * Set options. |
||
40 | * |
||
41 | * @param array|callable|string $options |
||
42 | * |
||
43 | * @return $this|mixed |
||
44 | */ |
||
45 | public function options($options = []) |
||
69 | |||
70 | /** |
||
71 | * @param array $groups |
||
72 | */ |
||
73 | |||
74 | /** |
||
75 | * Set option groups. |
||
76 | * |
||
77 | * eg: $group = [ |
||
78 | * [ |
||
79 | * 'label' => 'xxxx', |
||
80 | * 'options' => [ |
||
81 | * 1 => 'foo', |
||
82 | * 2 => 'bar', |
||
83 | * ... |
||
84 | * ], |
||
85 | * ... |
||
86 | * ] |
||
87 | * |
||
88 | * @param array $groups |
||
89 | * |
||
90 | * @return $this |
||
91 | */ |
||
92 | public function groups(array $groups) |
||
98 | |||
99 | /** |
||
100 | * Load options for other select on change. |
||
101 | * |
||
102 | * @param string $field |
||
103 | * @param string $sourceUrl |
||
104 | * @param string $idField |
||
105 | * @param string $textField |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function load($field, $sourceUrl, $idField = 'id', $textField = 'text') |
||
139 | |||
140 | /** |
||
141 | * Load options for other selects on change. |
||
142 | * |
||
143 | * @param string $fields |
||
144 | * @param string $sourceUrls |
||
145 | * @param string $idField |
||
146 | * @param string $textField |
||
147 | * |
||
148 | * @return $this |
||
149 | */ |
||
150 | public function loads($fields = [], $sourceUrls = [], $idField = 'id', $textField = 'text') |
||
191 | |||
192 | /** |
||
193 | * Load options from current selected resource(s). |
||
194 | * |
||
195 | * @param string $model |
||
196 | * @param string $idField |
||
197 | * @param string $textField |
||
198 | * |
||
199 | * @return $this |
||
200 | */ |
||
201 | View Code Duplication | public function model($model, $idField = 'id', $textField = 'name') |
|
231 | |||
232 | /** |
||
233 | * Load options from remote. |
||
234 | * |
||
235 | * @param string $url |
||
236 | * @param array $parameters |
||
237 | * @param array $options |
||
238 | * |
||
239 | * @return $this |
||
240 | */ |
||
241 | View Code Duplication | protected function loadRemoteOptions($url, $parameters = [], $options = []) |
|
269 | |||
270 | /** |
||
271 | * Load options from ajax results. |
||
272 | * |
||
273 | * @param string $url |
||
274 | * @param $idField |
||
275 | * @param $textField |
||
276 | * |
||
277 | * @return $this |
||
278 | */ |
||
279 | View Code Duplication | public function ajax($url, $idField = 'id', $textField = 'text') |
|
329 | |||
330 | /** |
||
331 | * Set config for select2. |
||
332 | * |
||
333 | * all configurations see https://select2.org/configuration/options-api |
||
334 | * |
||
335 | * @param string $key |
||
336 | * @param mixed $val |
||
337 | * |
||
338 | * @return $this |
||
339 | */ |
||
340 | public function config($key, $val) |
||
346 | |||
347 | /** |
||
348 | * {@inheritdoc} |
||
349 | */ |
||
350 | public function render() |
||
382 | } |
||
383 |
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: