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 = []) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param array $groups |
||
| 65 | */ |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Set option groups. |
||
| 69 | * |
||
| 70 | * eg: $group = [ |
||
| 71 | * [ |
||
| 72 | * 'label' => 'xxxx', |
||
| 73 | * 'options' => [ |
||
| 74 | * 1 => 'foo', |
||
| 75 | * 2 => 'bar', |
||
| 76 | * ... |
||
| 77 | * ], |
||
| 78 | * ... |
||
| 79 | * ] |
||
| 80 | * |
||
| 81 | * @param array $groups |
||
| 82 | * |
||
| 83 | * @return $this |
||
| 84 | */ |
||
| 85 | public function groups(array $groups) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Load options for other select on change. |
||
| 94 | * |
||
| 95 | * @param string $field |
||
| 96 | * @param string $sourceUrl |
||
| 97 | * @param string $idField |
||
| 98 | * @param string $textField |
||
| 99 | * |
||
| 100 | * @return $this |
||
| 101 | */ |
||
| 102 | public function load($field, $sourceUrl, $idField = 'id', $textField = 'text') |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Load options for other selects on change. |
||
| 135 | * |
||
| 136 | * @param string $fields |
||
| 137 | * @param string $sourceUrls |
||
| 138 | * @param string $idField |
||
| 139 | * @param string $textField |
||
| 140 | * |
||
| 141 | * @return $this |
||
| 142 | */ |
||
| 143 | public function loads($fields = [], $sourceUrls = [] , $idField = 'id', $textField = 'text') |
||
| 184 | |||
| 185 | /** |
||
| 186 | * Load options from remote. |
||
| 187 | * |
||
| 188 | * @param string $url |
||
| 189 | * @param array $parameters |
||
| 190 | * @param array $options |
||
| 191 | * |
||
| 192 | * @return $this |
||
| 193 | */ |
||
| 194 | View Code Duplication | protected function loadRemoteOptions($url, $parameters = [], $options = []) |
|
| 212 | |||
| 213 | /** |
||
| 214 | * Load options from ajax results. |
||
| 215 | * |
||
| 216 | * @param string $url |
||
| 217 | * @param $idField |
||
| 218 | * @param $textField |
||
| 219 | * |
||
| 220 | * @return $this |
||
| 221 | */ |
||
| 222 | public function ajax($url, $idField = 'id', $textField = 'text') |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Set config for select2. |
||
| 266 | * |
||
| 267 | * all configurations see https://select2.org/configuration/options-api |
||
| 268 | * |
||
| 269 | * @param string $key |
||
| 270 | * @param mixed $val |
||
| 271 | * |
||
| 272 | * @return $this |
||
| 273 | */ |
||
| 274 | public function config($key, $val) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * {@inheritdoc} |
||
| 283 | */ |
||
| 284 | public function render() |
||
| 312 | } |
||
| 313 |
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: