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 FormBuilder 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 FormBuilder, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace Anomaly\Streams\Platform\Ui\Form; |
||
| 39 | class FormBuilder |
||
| 40 | { |
||
| 41 | |||
| 42 | use DispatchesJobs; |
||
| 43 | use FiresCallbacks; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The ajax flag. |
||
| 47 | * |
||
| 48 | * @var bool |
||
| 49 | */ |
||
| 50 | protected $ajax = false; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The form handler. |
||
| 54 | * |
||
| 55 | * @var null|string |
||
| 56 | */ |
||
| 57 | protected $handler = null; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The form validator. |
||
| 61 | * |
||
| 62 | * @var null|string |
||
| 63 | */ |
||
| 64 | protected $validator = null; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The form repository. |
||
| 68 | * |
||
| 69 | * @var null|FormRepositoryInterface |
||
| 70 | */ |
||
| 71 | protected $repository = null; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The form model. |
||
| 75 | * |
||
| 76 | * @var null |
||
| 77 | */ |
||
| 78 | protected $model = null; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The entry object. |
||
| 82 | * |
||
| 83 | * @var null|int |
||
| 84 | */ |
||
| 85 | protected $entry = null; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The fields config. |
||
| 89 | * |
||
| 90 | * @var array|string |
||
| 91 | */ |
||
| 92 | protected $fields = []; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Fields to skip. |
||
| 96 | * |
||
| 97 | * @var array|string |
||
| 98 | */ |
||
| 99 | protected $skips = []; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * The actions config. |
||
| 103 | * |
||
| 104 | * @var array|string |
||
| 105 | */ |
||
| 106 | protected $actions = []; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * The buttons config. |
||
| 110 | * |
||
| 111 | * @var array|string |
||
| 112 | */ |
||
| 113 | protected $buttons = []; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * The form options. |
||
| 117 | * |
||
| 118 | * @var array |
||
| 119 | */ |
||
| 120 | protected $options = []; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The form sections. |
||
| 124 | * |
||
| 125 | * @var array |
||
| 126 | */ |
||
| 127 | protected $sections = []; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * The form assets. |
||
| 131 | * |
||
| 132 | * @var array |
||
| 133 | */ |
||
| 134 | protected $assets = []; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * The save flag. |
||
| 138 | * |
||
| 139 | * @var bool |
||
| 140 | */ |
||
| 141 | protected $save = true; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * The read only flag. |
||
| 145 | * |
||
| 146 | * @var bool |
||
| 147 | */ |
||
| 148 | protected $readOnly = false; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * The form object. |
||
| 152 | * |
||
| 153 | * @var Form |
||
| 154 | */ |
||
| 155 | protected $form; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Crate a new FormBuilder instance. |
||
| 159 | * |
||
| 160 | * @param Form $form |
||
| 161 | */ |
||
| 162 | public function __construct(Form $form) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Build the form. |
||
| 169 | * |
||
| 170 | * @param null $entry |
||
| 171 | * @return $this |
||
| 172 | */ |
||
| 173 | public function build($entry = null) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Make the form. |
||
| 190 | * |
||
| 191 | * @param null $entry |
||
| 192 | * @return $this |
||
| 193 | */ |
||
| 194 | public function make($entry = null) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Handle the form post. |
||
| 212 | * |
||
| 213 | * @param null $entry |
||
| 214 | * @return $this |
||
| 215 | * @throws \Exception |
||
| 216 | */ |
||
| 217 | public function handle($entry = null) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Trigger post operations |
||
| 231 | * for the form. |
||
| 232 | * |
||
| 233 | * @return $this |
||
| 234 | */ |
||
| 235 | public function post() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Validate the form. |
||
| 252 | * |
||
| 253 | * @return $this |
||
| 254 | */ |
||
| 255 | public function validate() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Flash form information to be |
||
| 265 | * used in conjunction with redirect |
||
| 266 | * type responses (not self handling). |
||
| 267 | */ |
||
| 268 | public function flash() |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Render the form. |
||
| 276 | * |
||
| 277 | * @param null $entry |
||
| 278 | * @return Response |
||
| 279 | */ |
||
| 280 | public function render($entry = null) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Fire field events. |
||
| 293 | * |
||
| 294 | * @param $trigger |
||
| 295 | * @param array $payload |
||
| 296 | */ |
||
| 297 | public function fireFieldEvents($trigger, array $payload = []) |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Save the form. |
||
| 307 | */ |
||
| 308 | public function saveForm() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Get the form object. |
||
| 315 | * |
||
| 316 | * @return Form |
||
| 317 | */ |
||
| 318 | public function getForm() |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Get the form presenter. |
||
| 325 | * |
||
| 326 | * @return FormPresenter |
||
| 327 | */ |
||
| 328 | public function getFormPresenter() |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Get the ajax flag. |
||
| 335 | * |
||
| 336 | * @return bool |
||
| 337 | */ |
||
| 338 | public function isAjax() |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Set the ajax flag. |
||
| 345 | * |
||
| 346 | * @param $ajax |
||
| 347 | * @return $this |
||
| 348 | */ |
||
| 349 | public function setAjax($ajax) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Get the handler. |
||
| 358 | * |
||
| 359 | * @return null|string |
||
| 360 | */ |
||
| 361 | public function getHandler() |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Set the handler. |
||
| 368 | * |
||
| 369 | * @param $handler |
||
| 370 | * @return $this |
||
| 371 | */ |
||
| 372 | public function setHandler($handler) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Get the validator. |
||
| 381 | * |
||
| 382 | * @return null|string |
||
| 383 | */ |
||
| 384 | public function getValidator() |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Set the validator. |
||
| 391 | * |
||
| 392 | * @param $validator |
||
| 393 | * @return $this |
||
| 394 | */ |
||
| 395 | public function setValidator($validator) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Get the repository. |
||
| 404 | * |
||
| 405 | * @return FormRepositoryInterface|null |
||
| 406 | */ |
||
| 407 | public function getRepository() |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Set the form repository. |
||
| 414 | * |
||
| 415 | * @param FormRepositoryInterface $repository |
||
| 416 | * @return $this |
||
| 417 | */ |
||
| 418 | public function setRepository(FormRepositoryInterface $repository) |
||
| 424 | |||
| 425 | /** |
||
| 426 | * Set the form model. |
||
| 427 | * |
||
| 428 | * @param $model |
||
| 429 | * @return $this |
||
| 430 | */ |
||
| 431 | public function setModel($model) |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Get the form model. |
||
| 440 | * |
||
| 441 | * @return null |
||
| 442 | */ |
||
| 443 | public function getModel() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * Set the entry object. |
||
| 450 | * |
||
| 451 | * @param $entry |
||
| 452 | * @return $this |
||
| 453 | */ |
||
| 454 | public function setEntry($entry) |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Get the entry object. |
||
| 463 | * |
||
| 464 | * @return null|EntryInterface|FieldInterface|mixed |
||
| 465 | */ |
||
| 466 | public function getEntry() |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Set the fields. |
||
| 473 | * |
||
| 474 | * @param $fields |
||
| 475 | * @return $this |
||
| 476 | */ |
||
| 477 | public function setFields($fields) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Get the fields. |
||
| 486 | * |
||
| 487 | * @return array |
||
| 488 | */ |
||
| 489 | public function getFields() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Add a field. |
||
| 496 | * |
||
| 497 | * @param $field |
||
| 498 | */ |
||
| 499 | public function addField($field) |
||
| 503 | |||
| 504 | /** |
||
| 505 | * Add fields. |
||
| 506 | * |
||
| 507 | * @param array $fields |
||
| 508 | */ |
||
| 509 | public function addFields(array $fields) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Get the skipped fields. |
||
| 516 | * |
||
| 517 | * @return array |
||
| 518 | */ |
||
| 519 | public function getSkips() |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Set the skipped fields. |
||
| 526 | * |
||
| 527 | * @param $skips |
||
| 528 | * @return $this |
||
| 529 | */ |
||
| 530 | public function setSkips($skips) |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Merge in skipped fields. |
||
| 539 | * |
||
| 540 | * @param array $skips |
||
| 541 | * @return $this |
||
| 542 | */ |
||
| 543 | public function mergeSkips(array $skips) |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Add a skipped field. |
||
| 552 | * |
||
| 553 | * @param $fieldSlug |
||
| 554 | * @return $this |
||
| 555 | */ |
||
| 556 | public function skipField($fieldSlug) |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Set the actions config. |
||
| 565 | * |
||
| 566 | * @param $actions |
||
| 567 | * @return $this |
||
| 568 | */ |
||
| 569 | public function setActions($actions) |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Add an action. |
||
| 578 | * |
||
| 579 | * @param $slug |
||
| 580 | * @param array $definition |
||
| 581 | * @return $this |
||
| 582 | */ |
||
| 583 | public function addAction($slug, array $definition = []) |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Get the actions config. |
||
| 596 | * |
||
| 597 | * @return array |
||
| 598 | */ |
||
| 599 | public function getActions() |
||
| 603 | |||
| 604 | /** |
||
| 605 | * Set the buttons config. |
||
| 606 | * |
||
| 607 | * @param $buttons |
||
| 608 | * @return $this |
||
| 609 | */ |
||
| 610 | public function setButtons($buttons) |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Get the buttons config. |
||
| 619 | * |
||
| 620 | * @return array |
||
| 621 | */ |
||
| 622 | public function getButtons() |
||
| 626 | |||
| 627 | /** |
||
| 628 | * The the options. |
||
| 629 | * |
||
| 630 | * @return array |
||
| 631 | */ |
||
| 632 | public function getOptions() |
||
| 636 | |||
| 637 | /** |
||
| 638 | * Set the options. |
||
| 639 | * |
||
| 640 | * @param array|string $options |
||
| 641 | * @return $this |
||
| 642 | */ |
||
| 643 | public function setOptions($options) |
||
| 649 | |||
| 650 | /** |
||
| 651 | * Merge in options. |
||
| 652 | * |
||
| 653 | * @param array|string $options |
||
| 654 | * @return $this |
||
| 655 | */ |
||
| 656 | public function mergeOptions($options) |
||
| 662 | |||
| 663 | /** |
||
| 664 | * Get the sections. |
||
| 665 | * |
||
| 666 | * @return array |
||
| 667 | */ |
||
| 668 | public function getSections() |
||
| 672 | |||
| 673 | /** |
||
| 674 | * Set the sections. |
||
| 675 | * |
||
| 676 | * @param array|Closure $sections |
||
| 677 | * @return $this |
||
| 678 | */ |
||
| 679 | public function setSections($sections) |
||
| 685 | |||
| 686 | /** |
||
| 687 | * Add a section. |
||
| 688 | * |
||
| 689 | * @param $slug |
||
| 690 | * @param array $section |
||
| 691 | * @param null $position |
||
| 692 | * @return $this |
||
| 693 | */ |
||
| 694 | View Code Duplication | public function addSection($slug, array $section, $position = null) |
|
| 707 | |||
| 708 | /** |
||
| 709 | * Add a section tab. |
||
| 710 | * |
||
| 711 | * @param $section |
||
| 712 | * @param $slug |
||
| 713 | * @param array $tab |
||
| 714 | * @param null $position |
||
| 715 | * @return $this |
||
| 716 | */ |
||
| 717 | View Code Duplication | public function addSectionTab($section, $slug, array $tab, $position = null) |
|
| 718 | { |
||
| 719 | $tabs = (array)array_get($this->sections, "{$section}.tabs"); |
||
| 720 | |||
| 721 | if ($position === null) { |
||
| 722 | $position = count($tabs) + 1; |
||
| 723 | } |
||
| 724 | |||
| 725 | $front = array_slice($tabs, 0, $position, true); |
||
| 726 | $back = array_slice($tabs, $position, count($tabs) - $position, true); |
||
| 727 | |||
| 728 | $tabs = $front + [$slug => $tab] + $back; |
||
| 729 | |||
| 730 | array_set($this->sections, "{$section}.tabs", $tabs); |
||
| 731 | |||
| 732 | return $this; |
||
| 733 | } |
||
| 734 | |||
| 735 | /** |
||
| 736 | * Get an option value. |
||
| 737 | * |
||
| 738 | * @param $key |
||
| 739 | * @param null $default |
||
| 740 | * @return mixed |
||
| 741 | */ |
||
| 742 | public function getOption($key, $default = null) |
||
| 746 | |||
| 747 | /** |
||
| 748 | * Set an option value. |
||
| 749 | * |
||
| 750 | * @param $key |
||
| 751 | * @param $value |
||
| 752 | * @return $this |
||
| 753 | */ |
||
| 754 | public function setOption($key, $value) |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Get the assets. |
||
| 763 | * |
||
| 764 | * @return array |
||
| 765 | */ |
||
| 766 | public function getAssets() |
||
| 770 | |||
| 771 | /** |
||
| 772 | * Set the assets. |
||
| 773 | * |
||
| 774 | * @param $assets |
||
| 775 | * @return $this |
||
| 776 | */ |
||
| 777 | public function setAssets($assets) |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Add an asset. |
||
| 786 | * |
||
| 787 | * @param $collection |
||
| 788 | * @param $asset |
||
| 789 | * @return $this |
||
| 790 | */ |
||
| 791 | View Code Duplication | public function addAsset($collection, $asset) |
|
| 801 | |||
| 802 | /** |
||
| 803 | * Get the form's stream. |
||
| 804 | * |
||
| 805 | * @return StreamInterface|null |
||
| 806 | */ |
||
| 807 | public function getFormStream() |
||
| 811 | |||
| 812 | /** |
||
| 813 | * Get a form option value. |
||
| 814 | * |
||
| 815 | * @param $key |
||
| 816 | * @param null $default |
||
| 817 | * @return mixed |
||
| 818 | */ |
||
| 819 | public function getFormOption($key, $default = null) |
||
| 823 | |||
| 824 | /** |
||
| 825 | * Set a form option value. |
||
| 826 | * |
||
| 827 | * @param $key |
||
| 828 | * @param $value |
||
| 829 | * @return $this |
||
| 830 | */ |
||
| 831 | public function setFormOption($key, $value) |
||
| 837 | |||
| 838 | /** |
||
| 839 | * Get the form options. |
||
| 840 | * |
||
| 841 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 842 | */ |
||
| 843 | public function getFormOptions() |
||
| 847 | |||
| 848 | /** |
||
| 849 | * Get the form model. |
||
| 850 | * |
||
| 851 | * @return \Anomaly\Streams\Platform\Entry\EntryModel|EloquentModel|null |
||
| 852 | */ |
||
| 853 | public function getFormModel() |
||
| 857 | |||
| 858 | /** |
||
| 859 | * Get the form entry. |
||
| 860 | * |
||
| 861 | * @return EloquentModel|EntryInterface|FieldInterface|AssignmentInterface |
||
| 862 | */ |
||
| 863 | public function getFormEntry() |
||
| 867 | |||
| 868 | /** |
||
| 869 | * Return the form entry's ID. |
||
| 870 | * |
||
| 871 | * @return int|mixed|null |
||
| 872 | */ |
||
| 873 | public function getFormEntryId() |
||
| 883 | |||
| 884 | /** |
||
| 885 | * Get the contextual entry ID. |
||
| 886 | * |
||
| 887 | * @return int|null |
||
| 888 | */ |
||
| 889 | public function getContextualId() |
||
| 893 | |||
| 894 | /** |
||
| 895 | * Get the form mode. |
||
| 896 | * |
||
| 897 | * @return null|string |
||
| 898 | */ |
||
| 899 | public function getFormMode() |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Set the form mode. |
||
| 906 | * |
||
| 907 | * @param $mode |
||
| 908 | * @return $this |
||
| 909 | */ |
||
| 910 | public function setFormMode($mode) |
||
| 916 | |||
| 917 | /** |
||
| 918 | * Get a form value. |
||
| 919 | * |
||
| 920 | * @param $key |
||
| 921 | * @param null $default |
||
| 922 | * @return mixed |
||
| 923 | */ |
||
| 924 | public function getFormValue($key, $default = null) |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Set a form value. |
||
| 931 | * |
||
| 932 | * @param $key |
||
| 933 | * @param $value |
||
| 934 | * @return $this |
||
| 935 | */ |
||
| 936 | public function setFormValue($key, $value) |
||
| 942 | |||
| 943 | /** |
||
| 944 | * Get the form values. |
||
| 945 | * |
||
| 946 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 947 | */ |
||
| 948 | public function getFormValues() |
||
| 952 | |||
| 953 | /** |
||
| 954 | * Reset the form. |
||
| 955 | * |
||
| 956 | * @return $this |
||
| 957 | */ |
||
| 958 | public function resetForm() |
||
| 966 | |||
| 967 | /** |
||
| 968 | * Get the form input. |
||
| 969 | * |
||
| 970 | * @return array |
||
| 971 | */ |
||
| 972 | public function getFormInput() |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Get the form data. |
||
| 981 | * |
||
| 982 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 983 | */ |
||
| 984 | public function getFormData() |
||
| 988 | |||
| 989 | /** |
||
| 990 | * Add form data. |
||
| 991 | * |
||
| 992 | * @param $key |
||
| 993 | * @param $value |
||
| 994 | * @return $this |
||
| 995 | */ |
||
| 996 | public function addFormData($key, $value) |
||
| 1002 | |||
| 1003 | /** |
||
| 1004 | * Ge the form response. |
||
| 1005 | * |
||
| 1006 | * @return null|Response |
||
| 1007 | */ |
||
| 1008 | public function getFormResponse() |
||
| 1012 | |||
| 1013 | /** |
||
| 1014 | * Set the form response. |
||
| 1015 | * |
||
| 1016 | * @param null|false|Response $response |
||
| 1017 | * @return $this |
||
| 1018 | */ |
||
| 1019 | public function setFormResponse(Response $response) |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Get the form content. |
||
| 1028 | * |
||
| 1029 | * @return null|string |
||
| 1030 | */ |
||
| 1031 | public function getFormContent() |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Get the form fields. |
||
| 1038 | * |
||
| 1039 | * @return Component\Field\FieldCollection |
||
| 1040 | */ |
||
| 1041 | public function getFormFields() |
||
| 1045 | |||
| 1046 | /** |
||
| 1047 | * Get the enabled form fields. |
||
| 1048 | * |
||
| 1049 | * @return Component\Field\FieldCollection |
||
| 1050 | */ |
||
| 1051 | public function getEnabledFormFields() |
||
| 1055 | |||
| 1056 | /** |
||
| 1057 | * Get the form field. |
||
| 1058 | * |
||
| 1059 | * @param $fieldSlug |
||
| 1060 | * @return FieldType |
||
| 1061 | */ |
||
| 1062 | public function getFormField($fieldSlug) |
||
| 1066 | |||
| 1067 | /** |
||
| 1068 | * Get the form attribute map. |
||
| 1069 | * |
||
| 1070 | * @return FieldType |
||
| 1071 | */ |
||
| 1072 | public function getFormFieldFromAttribute($attribute) |
||
| 1083 | |||
| 1084 | /** |
||
| 1085 | * Disable a form field. |
||
| 1086 | * |
||
| 1087 | * @param $fieldSlug |
||
| 1088 | * @return $this |
||
| 1089 | */ |
||
| 1090 | public function disableFormField($fieldSlug) |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Get the form field slugs. |
||
| 1099 | * |
||
| 1100 | * @param null $prefix |
||
| 1101 | * @return array |
||
| 1102 | */ |
||
| 1103 | public function getFormFieldSlugs($prefix = null) |
||
| 1114 | |||
| 1115 | /** |
||
| 1116 | * Get the form field names. |
||
| 1117 | * |
||
| 1118 | * @return array |
||
| 1119 | */ |
||
| 1120 | public function getFormFieldNames() |
||
| 1126 | |||
| 1127 | /** |
||
| 1128 | * Add a form field. |
||
| 1129 | * |
||
| 1130 | * @param FieldType $field |
||
| 1131 | * @return $this |
||
| 1132 | */ |
||
| 1133 | public function addFormField(FieldType $field) |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Set the form errors. |
||
| 1142 | * |
||
| 1143 | * @param MessageBag $errors |
||
| 1144 | * @return $this |
||
| 1145 | */ |
||
| 1146 | public function setFormErrors(MessageBag $errors) |
||
| 1152 | |||
| 1153 | /** |
||
| 1154 | * Get the form errors. |
||
| 1155 | * |
||
| 1156 | * @return null|MessageBag |
||
| 1157 | */ |
||
| 1158 | public function getFormErrors() |
||
| 1162 | |||
| 1163 | /** |
||
| 1164 | * Add an error to the form. |
||
| 1165 | * |
||
| 1166 | * @param $field |
||
| 1167 | * @param $message |
||
| 1168 | * @return $this |
||
| 1169 | */ |
||
| 1170 | public function addFormError($field, $message) |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Return whether the form has errors or not. |
||
| 1181 | * |
||
| 1182 | * @return bool |
||
| 1183 | */ |
||
| 1184 | public function hasFormErrors() |
||
| 1190 | |||
| 1191 | /** |
||
| 1192 | * Return whether the field has an error or not. |
||
| 1193 | * |
||
| 1194 | * @param $fieldName |
||
| 1195 | * @return bool |
||
| 1196 | */ |
||
| 1197 | public function hasFormError($fieldName) |
||
| 1201 | |||
| 1202 | /** |
||
| 1203 | * Get the form actions. |
||
| 1204 | * |
||
| 1205 | * @return ActionCollection |
||
| 1206 | */ |
||
| 1207 | public function getFormActions() |
||
| 1211 | |||
| 1212 | /** |
||
| 1213 | * Get the active form action. |
||
| 1214 | * |
||
| 1215 | * @return null|ActionInterface |
||
| 1216 | */ |
||
| 1217 | public function getActiveFormAction() |
||
| 1229 | |||
| 1230 | /** |
||
| 1231 | * Add a form button. |
||
| 1232 | * |
||
| 1233 | * @param ButtonInterface $button |
||
| 1234 | * @return $this |
||
| 1235 | */ |
||
| 1236 | public function addFormButton(ButtonInterface $button) |
||
| 1242 | |||
| 1243 | /** |
||
| 1244 | * Add a form section. |
||
| 1245 | * |
||
| 1246 | * @param $slug |
||
| 1247 | * @param array $section |
||
| 1248 | * @return $this |
||
| 1249 | */ |
||
| 1250 | public function addFormSection($slug, array $section) |
||
| 1256 | |||
| 1257 | /** |
||
| 1258 | * Set the form entry. |
||
| 1259 | * |
||
| 1260 | * @param $entry |
||
| 1261 | * @return $this |
||
| 1262 | */ |
||
| 1263 | public function setFormEntry($entry) |
||
| 1269 | |||
| 1270 | /** |
||
| 1271 | * Get a request value. |
||
| 1272 | * |
||
| 1273 | * @param $key |
||
| 1274 | * @param null $default |
||
| 1275 | * @return mixed |
||
| 1276 | */ |
||
| 1277 | public function getRequestValue($key, $default = null) |
||
| 1281 | |||
| 1282 | /** |
||
| 1283 | * Get a post value. |
||
| 1284 | * |
||
| 1285 | * @param $key |
||
| 1286 | * @param null $default |
||
| 1287 | * @return mixed |
||
| 1288 | */ |
||
| 1289 | public function getPostValue($key, $default = null) |
||
| 1293 | |||
| 1294 | /** |
||
| 1295 | * Return a post key flag. |
||
| 1296 | * |
||
| 1297 | * @param $key |
||
| 1298 | * @param null $default |
||
| 1299 | * @return mixed |
||
| 1300 | */ |
||
| 1301 | public function hasPostedInput($key) |
||
| 1305 | |||
| 1306 | /** |
||
| 1307 | * Return whether any post data exists. |
||
| 1308 | * |
||
| 1309 | * @return bool |
||
| 1310 | */ |
||
| 1311 | public function hasPostData() |
||
| 1322 | |||
| 1323 | /** |
||
| 1324 | * Return whether any post data exists. |
||
| 1325 | * |
||
| 1326 | * @return array |
||
| 1327 | */ |
||
| 1328 | public function getPostData() |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * Set the save flag. |
||
| 1337 | * |
||
| 1338 | * @param bool $save |
||
| 1339 | * @return $this |
||
| 1340 | */ |
||
| 1341 | public function setSave($save) |
||
| 1347 | |||
| 1348 | /** |
||
| 1349 | * Return the save flag. |
||
| 1350 | * |
||
| 1351 | * @return bool |
||
| 1352 | */ |
||
| 1353 | public function canSave() |
||
| 1357 | |||
| 1358 | /** |
||
| 1359 | * Set the read only flag. |
||
| 1360 | * |
||
| 1361 | * @param $readOnly |
||
| 1362 | * @return $this |
||
| 1363 | */ |
||
| 1364 | public function setReadOnly($readOnly) |
||
| 1370 | |||
| 1371 | /** |
||
| 1372 | * Return the read only flag. |
||
| 1373 | * |
||
| 1374 | * @return bool |
||
| 1375 | */ |
||
| 1376 | public function isReadOnly() |
||
| 1380 | } |
||
| 1381 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.