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 | * @var array |
||
| 38 | */ |
||
| 39 | protected $button = null; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Set options. |
||
| 43 | * |
||
| 44 | * @param array|callable|string $options |
||
| 45 | * |
||
| 46 | * @return $this|mixed |
||
| 47 | */ |
||
| 48 | 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') |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Load options from remote. |
||
| 146 | * |
||
| 147 | * @param string $url |
||
| 148 | * @param array $parameters |
||
| 149 | * @param array $options |
||
| 150 | * |
||
| 151 | * @return $this |
||
| 152 | */ |
||
| 153 | protected function loadRemoteOptions($url, $parameters = [], $options = []) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Load options from ajax results. |
||
| 178 | * |
||
| 179 | * @param string $url |
||
| 180 | * @param $idField |
||
| 181 | * @param $textField |
||
| 182 | * |
||
| 183 | * @return $this |
||
| 184 | */ |
||
| 185 | View Code Duplication | public function ajax($url, $idField = 'id', $textField = 'text') |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Set config for select2. |
||
| 231 | * |
||
| 232 | * all configurations see https://select2.org/configuration/options-api |
||
| 233 | * |
||
| 234 | * @param string $key |
||
| 235 | * @param mixed $val |
||
| 236 | * |
||
| 237 | * @return $this |
||
| 238 | */ |
||
| 239 | public function config($key, $val) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * add btn group for select2. |
||
| 248 | * |
||
| 249 | * @param $text |
||
| 250 | * @param $btn_url |
||
| 251 | * @param $ajax_url |
||
| 252 | * @return $this |
||
| 253 | * @internal param string $key |
||
| 254 | * @internal param mixed $val |
||
| 255 | * |
||
| 256 | */ |
||
| 257 | public function addButton($text, $btn_url ,$ajax_url) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * {@inheritdoc} |
||
| 287 | */ |
||
| 288 | public function render() |
||
| 319 | } |
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: