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:
Complex classes like Form often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Form, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 75 | class Form implements Renderable |
||
| 76 | { |
||
| 77 | use HasHooks; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Remove flag in `has many` form. |
||
| 81 | */ |
||
| 82 | const REMOVE_FLAG_NAME = '_remove_'; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Eloquent model of the form. |
||
| 86 | * |
||
| 87 | * @var Model |
||
| 88 | */ |
||
| 89 | protected $model; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @var \Illuminate\Validation\Validator |
||
| 93 | */ |
||
| 94 | protected $validator; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @var Builder |
||
| 98 | */ |
||
| 99 | protected $builder; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Data for save to current model from input. |
||
| 103 | * |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | protected $updates = []; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Data for save to model's relations from input. |
||
| 110 | * |
||
| 111 | * @var array |
||
| 112 | */ |
||
| 113 | protected $relations = []; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Input data. |
||
| 117 | * |
||
| 118 | * @var array |
||
| 119 | */ |
||
| 120 | protected $inputs = []; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * @var Layout |
||
| 124 | */ |
||
| 125 | protected $layout; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Available fields. |
||
| 129 | * |
||
| 130 | * @var array |
||
| 131 | */ |
||
| 132 | public static $availableFields = [ |
||
| 133 | 'button' => Field\Button::class, |
||
| 134 | 'checkbox' => Field\Checkbox::class, |
||
| 135 | 'color' => Field\Color::class, |
||
| 136 | 'currency' => Field\Currency::class, |
||
| 137 | 'date' => Field\Date::class, |
||
| 138 | 'dateRange' => Field\DateRange::class, |
||
| 139 | 'datetime' => Field\Datetime::class, |
||
| 140 | 'dateTimeRange' => Field\DatetimeRange::class, |
||
| 141 | 'datetimeRange' => Field\DatetimeRange::class, |
||
| 142 | 'decimal' => Field\Decimal::class, |
||
| 143 | 'display' => Field\Display::class, |
||
| 144 | 'divider' => Field\Divider::class, |
||
| 145 | 'embeds' => Field\Embeds::class, |
||
| 146 | 'email' => Field\Email::class, |
||
| 147 | 'file' => Field\File::class, |
||
| 148 | 'hasMany' => Field\HasMany::class, |
||
| 149 | 'hidden' => Field\Hidden::class, |
||
| 150 | 'id' => Field\Id::class, |
||
| 151 | 'image' => Field\Image::class, |
||
| 152 | 'ip' => Field\Ip::class, |
||
| 153 | 'mobile' => Field\Mobile::class, |
||
| 154 | 'month' => Field\Month::class, |
||
| 155 | 'multipleSelect' => Field\MultipleSelect::class, |
||
| 156 | 'number' => Field\Number::class, |
||
| 157 | 'password' => Field\Password::class, |
||
| 158 | 'radio' => Field\Radio::class, |
||
| 159 | 'rate' => Field\Rate::class, |
||
| 160 | 'select' => Field\Select::class, |
||
| 161 | 'slider' => Field\Slider::class, |
||
| 162 | 'switch' => Field\SwitchField::class, |
||
| 163 | 'text' => Field\Text::class, |
||
| 164 | 'textarea' => Field\Textarea::class, |
||
| 165 | 'time' => Field\Time::class, |
||
| 166 | 'timeRange' => Field\TimeRange::class, |
||
| 167 | 'url' => Field\Url::class, |
||
| 168 | 'year' => Field\Year::class, |
||
| 169 | 'html' => Field\Html::class, |
||
| 170 | 'tags' => Field\Tags::class, |
||
| 171 | 'icon' => Field\Icon::class, |
||
| 172 | 'multipleFile' => Field\MultipleFile::class, |
||
| 173 | 'multipleImage' => Field\MultipleImage::class, |
||
| 174 | 'captcha' => Field\Captcha::class, |
||
| 175 | 'listbox' => Field\Listbox::class, |
||
| 176 | 'table' => Field\Table::class, |
||
| 177 | 'timezone' => Field\Timezone::class, |
||
| 178 | 'keyValue' => Field\KeyValue::class, |
||
| 179 | 'list' => Field\ListField::class, |
||
| 180 | ]; |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Form field alias. |
||
| 184 | * |
||
| 185 | * @var array |
||
| 186 | */ |
||
| 187 | public static $fieldAlias = []; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Ignored saving fields. |
||
| 191 | * |
||
| 192 | * @var array |
||
| 193 | */ |
||
| 194 | protected $ignored = []; |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Collected field assets. |
||
| 198 | * |
||
| 199 | * @var array |
||
| 200 | */ |
||
| 201 | protected static $collectedAssets = []; |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @var Form\Tab |
||
| 205 | */ |
||
| 206 | protected $tab = null; |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Field rows in form. |
||
| 210 | * |
||
| 211 | * @var array |
||
| 212 | */ |
||
| 213 | public $rows = []; |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @var bool |
||
| 217 | */ |
||
| 218 | protected $isSoftDeletes = false; |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Initialization closure array. |
||
| 222 | * |
||
| 223 | * @var []Closure |
||
| 224 | */ |
||
| 225 | protected static $initCallbacks; |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Create a new form instance. |
||
| 229 | * |
||
| 230 | * @param $model |
||
| 231 | * @param \Closure $callback |
||
| 232 | */ |
||
| 233 | public function __construct($model, Closure $callback = null) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Initialize with user pre-defined default disables, etc. |
||
| 252 | * |
||
| 253 | * @param Closure $callback |
||
| 254 | */ |
||
| 255 | public static function init(Closure $callback = null) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Call the initialization closure array in sequence. |
||
| 262 | */ |
||
| 263 | protected function callInitCallbacks() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @param Field $field |
||
| 276 | * |
||
| 277 | * @return $this |
||
| 278 | */ |
||
| 279 | public function pushField(Field $field) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @return Model |
||
| 291 | */ |
||
| 292 | public function model() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @return Builder |
||
| 299 | */ |
||
| 300 | public function builder() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Generate a edit form. |
||
| 307 | * |
||
| 308 | * @param $id |
||
| 309 | * |
||
| 310 | * @return $this |
||
| 311 | */ |
||
| 312 | public function edit($id) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Use tab to split form. |
||
| 324 | * |
||
| 325 | * @param string $title |
||
| 326 | * @param Closure $content |
||
| 327 | * |
||
| 328 | * @return $this |
||
| 329 | */ |
||
| 330 | public function tab($title, Closure $content, $active = false) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * Get Tab instance. |
||
| 339 | * |
||
| 340 | * @return Tab |
||
| 341 | */ |
||
| 342 | public function getTab() |
||
| 350 | |||
| 351 | /** |
||
| 352 | * Destroy data entity and remove files. |
||
| 353 | * |
||
| 354 | * @param $id |
||
| 355 | * |
||
| 356 | * @return mixed |
||
| 357 | */ |
||
| 358 | public function destroy($id) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Remove files in record. |
||
| 405 | * |
||
| 406 | * @param Model $model |
||
| 407 | * @param bool $forceDelete |
||
| 408 | */ |
||
| 409 | protected function deleteFiles(Model $model, $forceDelete = false) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Store a new record. |
||
| 429 | * |
||
| 430 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\Http\JsonResponse |
||
| 431 | */ |
||
| 432 | public function store() |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @param MessageBag $message |
||
| 470 | * |
||
| 471 | * @return $this|\Illuminate\Http\JsonResponse |
||
| 472 | */ |
||
| 473 | protected function responseValidationError(MessageBag $message) |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Get ajax response. |
||
| 488 | * |
||
| 489 | * @param string $message |
||
| 490 | * |
||
| 491 | * @return bool|\Illuminate\Http\JsonResponse |
||
| 492 | */ |
||
| 493 | protected function ajaxResponse($message) |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Prepare input data for insert or update. |
||
| 510 | * |
||
| 511 | * @param array $data |
||
| 512 | * |
||
| 513 | * @return mixed |
||
| 514 | */ |
||
| 515 | protected function prepare($data = []) |
||
| 531 | |||
| 532 | /** |
||
| 533 | * Remove ignored fields from input. |
||
| 534 | * |
||
| 535 | * @param array $input |
||
| 536 | * |
||
| 537 | * @return array |
||
| 538 | */ |
||
| 539 | protected function removeIgnoredFields($input) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Get inputs for relations. |
||
| 548 | * |
||
| 549 | * @param array $inputs |
||
| 550 | * |
||
| 551 | * @return array |
||
| 552 | */ |
||
| 553 | protected function getRelationInputs($inputs = []) |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Handle update. |
||
| 574 | * |
||
| 575 | * @param int $id |
||
| 576 | * @param null $data |
||
| 577 | * |
||
| 578 | * @return bool|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response|mixed|null|Response |
||
| 579 | */ |
||
| 580 | public function update($id, $data = null) |
||
| 637 | |||
| 638 | /** |
||
| 639 | * Get RedirectResponse after store. |
||
| 640 | * |
||
| 641 | * @return \Illuminate\Http\RedirectResponse |
||
| 642 | */ |
||
| 643 | protected function redirectAfterStore() |
||
| 651 | |||
| 652 | /** |
||
| 653 | * Get RedirectResponse after update. |
||
| 654 | * |
||
| 655 | * @param mixed $key |
||
| 656 | * |
||
| 657 | * @return \Illuminate\Http\RedirectResponse |
||
| 658 | */ |
||
| 659 | protected function redirectAfterUpdate($key) |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Get RedirectResponse after data saving. |
||
| 668 | * |
||
| 669 | * @param string $resourcesPath |
||
| 670 | * @param string $key |
||
| 671 | * |
||
| 672 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
||
| 673 | */ |
||
| 674 | protected function redirectAfterSaving($resourcesPath, $key) |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Check if request is from editable. |
||
| 696 | * |
||
| 697 | * @param array $input |
||
| 698 | * |
||
| 699 | * @return bool |
||
| 700 | */ |
||
| 701 | protected function isEditable(array $input = []) |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Handle updates for single column. |
||
| 708 | * |
||
| 709 | * @param int $id |
||
| 710 | * @param array $data |
||
| 711 | * |
||
| 712 | * @return array|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|Response |
||
| 713 | */ |
||
| 714 | protected function handleColumnUpdates($id, $data) |
||
| 731 | |||
| 732 | /** |
||
| 733 | * Handle editable update. |
||
| 734 | * |
||
| 735 | * @param array $input |
||
| 736 | * |
||
| 737 | * @return array |
||
| 738 | */ |
||
| 739 | protected function handleEditable(array $input = []) |
||
| 751 | |||
| 752 | /** |
||
| 753 | * @param array $input |
||
| 754 | * |
||
| 755 | * @return array |
||
| 756 | */ |
||
| 757 | protected function handleFileDelete(array $input = []) |
||
| 768 | |||
| 769 | /** |
||
| 770 | * @param array $input |
||
| 771 | * |
||
| 772 | * @return array |
||
| 773 | */ |
||
| 774 | protected function handleFileSort(array $input = []) |
||
| 794 | |||
| 795 | /** |
||
| 796 | * Handle orderable update. |
||
| 797 | * |
||
| 798 | * @param int $id |
||
| 799 | * @param array $input |
||
| 800 | * |
||
| 801 | * @return bool |
||
| 802 | */ |
||
| 803 | protected function handleOrderable($id, array $input = []) |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Update relation data. |
||
| 820 | * |
||
| 821 | * @param array $relationsData |
||
| 822 | * |
||
| 823 | * @return void |
||
| 824 | */ |
||
| 825 | protected function updateRelation($relationsData) |
||
| 932 | |||
| 933 | /** |
||
| 934 | * Prepare input data for update. |
||
| 935 | * |
||
| 936 | * @param array $updates |
||
| 937 | * @param bool $oneToOneRelation If column is one-to-one relation. |
||
| 938 | * |
||
| 939 | * @return array |
||
| 940 | */ |
||
| 941 | protected function prepareUpdate(array $updates, $oneToOneRelation = false) |
||
| 973 | |||
| 974 | /** |
||
| 975 | * @param string|array $columns |
||
| 976 | * @param bool $containsDot |
||
| 977 | * |
||
| 978 | * @return bool |
||
| 979 | */ |
||
| 980 | protected function isInvalidColumn($columns, $containsDot = false) |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Prepare input data for insert. |
||
| 994 | * |
||
| 995 | * @param $inserts |
||
| 996 | * |
||
| 997 | * @return array |
||
| 998 | */ |
||
| 999 | protected function prepareInsert($inserts) |
||
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Is input data is has-one relation. |
||
| 1025 | * |
||
| 1026 | * @param array $inserts |
||
| 1027 | * |
||
| 1028 | * @return bool |
||
| 1029 | */ |
||
| 1030 | protected function isHasOneRelation($inserts) |
||
| 1044 | |||
| 1045 | /** |
||
| 1046 | * Ignore fields to save. |
||
| 1047 | * |
||
| 1048 | * @param string|array $fields |
||
| 1049 | * |
||
| 1050 | * @return $this |
||
| 1051 | */ |
||
| 1052 | public function ignore($fields) |
||
| 1058 | |||
| 1059 | /** |
||
| 1060 | * @param array $data |
||
| 1061 | * @param string|array $columns |
||
| 1062 | * |
||
| 1063 | * @return array|mixed |
||
| 1064 | */ |
||
| 1065 | View Code Duplication | protected function getDataByColumn($data, $columns) |
|
| 1083 | |||
| 1084 | /** |
||
| 1085 | * Find field object by column. |
||
| 1086 | * |
||
| 1087 | * @param $column |
||
| 1088 | * |
||
| 1089 | * @return mixed |
||
| 1090 | */ |
||
| 1091 | protected function getFieldByColumn($column) |
||
| 1103 | |||
| 1104 | /** |
||
| 1105 | * Set original data for each field. |
||
| 1106 | * |
||
| 1107 | * @return void |
||
| 1108 | */ |
||
| 1109 | protected function setFieldOriginalValue() |
||
| 1119 | |||
| 1120 | /** |
||
| 1121 | * Set all fields value in form. |
||
| 1122 | * |
||
| 1123 | * @param $id |
||
| 1124 | * |
||
| 1125 | * @return void |
||
| 1126 | */ |
||
| 1127 | protected function setFieldValue($id) |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Add a fieldset to form. |
||
| 1154 | * |
||
| 1155 | * @param string $title |
||
| 1156 | * @param Closure $setCallback |
||
| 1157 | * |
||
| 1158 | * @return Field\Fieldset |
||
| 1159 | */ |
||
| 1160 | View Code Duplication | public function fieldset(string $title, Closure $setCallback) |
|
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Don't snake case attributes. |
||
| 1175 | * |
||
| 1176 | * @param Model $model |
||
| 1177 | * |
||
| 1178 | * @return void |
||
| 1179 | */ |
||
| 1180 | protected static function doNotSnakeAttributes(Model $model) |
||
| 1186 | |||
| 1187 | /** |
||
| 1188 | * Get validation messages. |
||
| 1189 | * |
||
| 1190 | * @param array $input |
||
| 1191 | * |
||
| 1192 | * @return MessageBag|bool |
||
| 1193 | */ |
||
| 1194 | public function validationMessages($input) |
||
| 1213 | |||
| 1214 | /** |
||
| 1215 | * Merge validation messages from input validators. |
||
| 1216 | * |
||
| 1217 | * @param \Illuminate\Validation\Validator[] $validators |
||
| 1218 | * |
||
| 1219 | * @return MessageBag |
||
| 1220 | */ |
||
| 1221 | protected function mergeValidationMessages($validators) |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Get all relations of model from callable. |
||
| 1234 | * |
||
| 1235 | * @return array |
||
| 1236 | */ |
||
| 1237 | public function getRelations() |
||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * Set action for form. |
||
| 1267 | * |
||
| 1268 | * @param string $action |
||
| 1269 | * |
||
| 1270 | * @return $this |
||
| 1271 | */ |
||
| 1272 | public function setAction($action) |
||
| 1278 | |||
| 1279 | /** |
||
| 1280 | * Set field and label width in current form. |
||
| 1281 | * |
||
| 1282 | * @param int $fieldWidth |
||
| 1283 | * @param int $labelWidth |
||
| 1284 | * |
||
| 1285 | * @return $this |
||
| 1286 | */ |
||
| 1287 | public function setWidth($fieldWidth = 8, $labelWidth = 2) |
||
| 1298 | |||
| 1299 | /** |
||
| 1300 | * Set view for form. |
||
| 1301 | * |
||
| 1302 | * @param string $view |
||
| 1303 | * |
||
| 1304 | * @return $this |
||
| 1305 | */ |
||
| 1306 | public function setView($view) |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Set title for form. |
||
| 1315 | * |
||
| 1316 | * @param string $title |
||
| 1317 | * |
||
| 1318 | * @return $this |
||
| 1319 | */ |
||
| 1320 | public function setTitle($title = '') |
||
| 1326 | |||
| 1327 | /** |
||
| 1328 | * Add a row in form. |
||
| 1329 | * |
||
| 1330 | * @param Closure $callback |
||
| 1331 | * |
||
| 1332 | * @return $this |
||
| 1333 | */ |
||
| 1334 | public function row(Closure $callback) |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * Tools setting for form. |
||
| 1343 | * |
||
| 1344 | * @param Closure $callback |
||
| 1345 | */ |
||
| 1346 | public function tools(Closure $callback) |
||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * @param Closure|null $callback |
||
| 1353 | * |
||
| 1354 | * @return Form\Tools |
||
| 1355 | */ |
||
| 1356 | public function header(Closure $callback = null) |
||
| 1364 | |||
| 1365 | /** |
||
| 1366 | * Indicates if current form page is creating. |
||
| 1367 | * |
||
| 1368 | * @return bool |
||
| 1369 | */ |
||
| 1370 | public function isCreating() |
||
| 1374 | |||
| 1375 | /** |
||
| 1376 | * Indicates if current form page is editing. |
||
| 1377 | * |
||
| 1378 | * @return bool |
||
| 1379 | */ |
||
| 1380 | public function isEditing() |
||
| 1384 | |||
| 1385 | /** |
||
| 1386 | * Disable form submit. |
||
| 1387 | * |
||
| 1388 | * @param bool $disable |
||
| 1389 | * |
||
| 1390 | * @return $this |
||
| 1391 | * |
||
| 1392 | * @deprecated |
||
| 1393 | */ |
||
| 1394 | public function disableSubmit(bool $disable = true) |
||
| 1400 | |||
| 1401 | /** |
||
| 1402 | * Disable form reset. |
||
| 1403 | * |
||
| 1404 | * @param bool $disable |
||
| 1405 | * |
||
| 1406 | * @return $this |
||
| 1407 | * |
||
| 1408 | * @deprecated |
||
| 1409 | */ |
||
| 1410 | public function disableReset(bool $disable = true) |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * Disable View Checkbox on footer. |
||
| 1419 | * |
||
| 1420 | * @param bool $disable |
||
| 1421 | * |
||
| 1422 | * @return $this |
||
| 1423 | */ |
||
| 1424 | public function disableViewCheck(bool $disable = true) |
||
| 1430 | |||
| 1431 | /** |
||
| 1432 | * Disable Editing Checkbox on footer. |
||
| 1433 | * |
||
| 1434 | * @param bool $disable |
||
| 1435 | * |
||
| 1436 | * @return $this |
||
| 1437 | */ |
||
| 1438 | public function disableEditingCheck(bool $disable = true) |
||
| 1444 | |||
| 1445 | /** |
||
| 1446 | * Disable Creating Checkbox on footer. |
||
| 1447 | * |
||
| 1448 | * @param bool $disable |
||
| 1449 | * |
||
| 1450 | * @return $this |
||
| 1451 | */ |
||
| 1452 | public function disableCreatingCheck(bool $disable = true) |
||
| 1458 | |||
| 1459 | /** |
||
| 1460 | * Footer setting for form. |
||
| 1461 | * |
||
| 1462 | * @param Closure $callback |
||
| 1463 | */ |
||
| 1464 | public function footer(Closure $callback = null) |
||
| 1472 | |||
| 1473 | /** |
||
| 1474 | * Get current resource route url. |
||
| 1475 | * |
||
| 1476 | * @param int $slice |
||
| 1477 | * |
||
| 1478 | * @return string |
||
| 1479 | */ |
||
| 1480 | public function resource($slice = -2) |
||
| 1490 | |||
| 1491 | /** |
||
| 1492 | * Render the form contents. |
||
| 1493 | * |
||
| 1494 | * @return string |
||
| 1495 | */ |
||
| 1496 | public function render() |
||
| 1504 | |||
| 1505 | /** |
||
| 1506 | * Get or set input data. |
||
| 1507 | * |
||
| 1508 | * @param string $key |
||
| 1509 | * @param null $value |
||
| 1510 | * |
||
| 1511 | * @return array|mixed |
||
| 1512 | */ |
||
| 1513 | public function input($key, $value = null) |
||
| 1521 | |||
| 1522 | /** |
||
| 1523 | * Register custom field. |
||
| 1524 | * |
||
| 1525 | * @param string $abstract |
||
| 1526 | * @param string $class |
||
| 1527 | * |
||
| 1528 | * @return void |
||
| 1529 | */ |
||
| 1530 | public static function extend($abstract, $class) |
||
| 1534 | |||
| 1535 | /** |
||
| 1536 | * Set form field alias. |
||
| 1537 | * |
||
| 1538 | * @param string $field |
||
| 1539 | * @param string $alias |
||
| 1540 | * |
||
| 1541 | * @return void |
||
| 1542 | */ |
||
| 1543 | public static function alias($field, $alias) |
||
| 1547 | |||
| 1548 | /** |
||
| 1549 | * Remove registered field. |
||
| 1550 | * |
||
| 1551 | * @param array|string $abstract |
||
| 1552 | */ |
||
| 1553 | public static function forget($abstract) |
||
| 1557 | |||
| 1558 | /** |
||
| 1559 | * Find field class. |
||
| 1560 | * |
||
| 1561 | * @param string $method |
||
| 1562 | * |
||
| 1563 | * @return bool|mixed |
||
| 1564 | */ |
||
| 1565 | public static function findFieldClass($method) |
||
| 1580 | |||
| 1581 | /** |
||
| 1582 | * Collect assets required by registered field. |
||
| 1583 | * |
||
| 1584 | * @return array |
||
| 1585 | */ |
||
| 1586 | public static function collectFieldAssets() |
||
| 1611 | |||
| 1612 | /** |
||
| 1613 | * Add a new layout column. |
||
| 1614 | * |
||
| 1615 | * @param int $width |
||
| 1616 | * @param \Closure $closure |
||
| 1617 | * |
||
| 1618 | * @return $this |
||
| 1619 | */ |
||
| 1620 | View Code Duplication | public function column($width, \Closure $closure) |
|
| 1628 | |||
| 1629 | /** |
||
| 1630 | * Initialize filter layout. |
||
| 1631 | */ |
||
| 1632 | protected function initLayout() |
||
| 1636 | |||
| 1637 | /** |
||
| 1638 | * Getter. |
||
| 1639 | * |
||
| 1640 | * @param string $name |
||
| 1641 | * |
||
| 1642 | * @return array|mixed |
||
| 1643 | */ |
||
| 1644 | public function __get($name) |
||
| 1648 | |||
| 1649 | /** |
||
| 1650 | * Setter. |
||
| 1651 | * |
||
| 1652 | * @param string $name |
||
| 1653 | * @param mixed $value |
||
| 1654 | * |
||
| 1655 | * @return array |
||
| 1656 | */ |
||
| 1657 | public function __set($name, $value) |
||
| 1661 | |||
| 1662 | /** |
||
| 1663 | * Generate a Field object and add to form builder if Field exists. |
||
| 1664 | * |
||
| 1665 | * @param string $method |
||
| 1666 | * @param array $arguments |
||
| 1667 | * |
||
| 1668 | * @return Field |
||
| 1669 | */ |
||
| 1670 | public function __call($method, $arguments) |
||
| 1686 | |||
| 1687 | /** |
||
| 1688 | * @return Layout |
||
| 1689 | */ |
||
| 1690 | public function getLayout(): Layout |
||
| 1694 | } |
||
| 1695 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: