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 skips. |
||
| 539 | * |
||
| 540 | * @param array|string $skips |
||
| 541 | * @return $this |
||
| 542 | */ |
||
| 543 | public function mergeSkips($skips) { |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Add a skipped field. |
||
| 551 | * |
||
| 552 | * @param $fieldSlug |
||
| 553 | * @return $this |
||
| 554 | */ |
||
| 555 | public function skipField($fieldSlug) |
||
| 561 | |||
| 562 | /** |
||
| 563 | * Set the actions config. |
||
| 564 | * |
||
| 565 | * @param $actions |
||
| 566 | * @return $this |
||
| 567 | */ |
||
| 568 | public function setActions($actions) |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Add an action. |
||
| 577 | * |
||
| 578 | * @param $slug |
||
| 579 | * @param array $definition |
||
| 580 | * @return $this |
||
| 581 | */ |
||
| 582 | public function addAction($slug, array $definition = []) |
||
| 592 | |||
| 593 | /** |
||
| 594 | * Get the actions config. |
||
| 595 | * |
||
| 596 | * @return array |
||
| 597 | */ |
||
| 598 | public function getActions() |
||
| 602 | |||
| 603 | /** |
||
| 604 | * Set the buttons config. |
||
| 605 | * |
||
| 606 | * @param $buttons |
||
| 607 | * @return $this |
||
| 608 | */ |
||
| 609 | public function setButtons($buttons) |
||
| 615 | |||
| 616 | /** |
||
| 617 | * Get the buttons config. |
||
| 618 | * |
||
| 619 | * @return array |
||
| 620 | */ |
||
| 621 | public function getButtons() |
||
| 625 | |||
| 626 | /** |
||
| 627 | * The the options. |
||
| 628 | * |
||
| 629 | * @return array |
||
| 630 | */ |
||
| 631 | public function getOptions() |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Set the options. |
||
| 638 | * |
||
| 639 | * @param array|string $options |
||
| 640 | * @return $this |
||
| 641 | */ |
||
| 642 | public function setOptions($options) |
||
| 648 | |||
| 649 | /** |
||
| 650 | * Merge in options. |
||
| 651 | * |
||
| 652 | * @param array|string $options |
||
| 653 | * @return $this |
||
| 654 | */ |
||
| 655 | public function mergeOptions($options) |
||
| 661 | |||
| 662 | /** |
||
| 663 | * Get the sections. |
||
| 664 | * |
||
| 665 | * @return array |
||
| 666 | */ |
||
| 667 | public function getSections() |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Set the sections. |
||
| 674 | * |
||
| 675 | * @param array|Closure $sections |
||
| 676 | * @return $this |
||
| 677 | */ |
||
| 678 | public function setSections($sections) |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Add a section. |
||
| 687 | * |
||
| 688 | * @param $slug |
||
| 689 | * @param array $section |
||
| 690 | * @return $this |
||
| 691 | */ |
||
| 692 | public function addSection($slug, array $section) |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Add a section tab. |
||
| 701 | * |
||
| 702 | * @param $section |
||
| 703 | * @param $slug |
||
| 704 | * @param array $tab |
||
| 705 | * @return $this |
||
| 706 | */ |
||
| 707 | public function addSectionTab($section, $slug, array $tab) |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Get an option value. |
||
| 716 | * |
||
| 717 | * @param $key |
||
| 718 | * @param null $default |
||
| 719 | * @return mixed |
||
| 720 | */ |
||
| 721 | public function getOption($key, $default = null) |
||
| 725 | |||
| 726 | /** |
||
| 727 | * Set an option value. |
||
| 728 | * |
||
| 729 | * @param $key |
||
| 730 | * @param $value |
||
| 731 | * @return $this |
||
| 732 | */ |
||
| 733 | public function setOption($key, $value) |
||
| 739 | |||
| 740 | /** |
||
| 741 | * Get the assets. |
||
| 742 | * |
||
| 743 | * @return array |
||
| 744 | */ |
||
| 745 | public function getAssets() |
||
| 749 | |||
| 750 | /** |
||
| 751 | * Set the assets. |
||
| 752 | * |
||
| 753 | * @param $assets |
||
| 754 | * @return $this |
||
| 755 | */ |
||
| 756 | public function setAssets($assets) |
||
| 762 | |||
| 763 | /** |
||
| 764 | * Add an asset. |
||
| 765 | * |
||
| 766 | * @param $collection |
||
| 767 | * @param $asset |
||
| 768 | * @return $this |
||
| 769 | */ |
||
| 770 | View Code Duplication | public function addAsset($collection, $asset) |
|
| 780 | |||
| 781 | /** |
||
| 782 | * Get the form's stream. |
||
| 783 | * |
||
| 784 | * @return StreamInterface|null |
||
| 785 | */ |
||
| 786 | public function getFormStream() |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Get a form option value. |
||
| 793 | * |
||
| 794 | * @param $key |
||
| 795 | * @param null $default |
||
| 796 | * @return mixed |
||
| 797 | */ |
||
| 798 | public function getFormOption($key, $default = null) |
||
| 802 | |||
| 803 | /** |
||
| 804 | * Set a form option value. |
||
| 805 | * |
||
| 806 | * @param $key |
||
| 807 | * @param $value |
||
| 808 | * @return $this |
||
| 809 | */ |
||
| 810 | public function setFormOption($key, $value) |
||
| 816 | |||
| 817 | /** |
||
| 818 | * Get the form options. |
||
| 819 | * |
||
| 820 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 821 | */ |
||
| 822 | public function getFormOptions() |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Get the form model. |
||
| 829 | * |
||
| 830 | * @return \Anomaly\Streams\Platform\Entry\EntryModel|EloquentModel|null |
||
| 831 | */ |
||
| 832 | public function getFormModel() |
||
| 836 | |||
| 837 | /** |
||
| 838 | * Get the form entry. |
||
| 839 | * |
||
| 840 | * @return EloquentModel|EntryInterface|FieldInterface|AssignmentInterface |
||
| 841 | */ |
||
| 842 | public function getFormEntry() |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Return the form entry's ID. |
||
| 849 | * |
||
| 850 | * @return int|mixed|null |
||
| 851 | */ |
||
| 852 | public function getFormEntryId() |
||
| 862 | |||
| 863 | /** |
||
| 864 | * Get the contextual entry ID. |
||
| 865 | * |
||
| 866 | * @return int|null |
||
| 867 | */ |
||
| 868 | public function getContextualId() |
||
| 872 | |||
| 873 | /** |
||
| 874 | * Get the form mode. |
||
| 875 | * |
||
| 876 | * @return null|string |
||
| 877 | */ |
||
| 878 | public function getFormMode() |
||
| 882 | |||
| 883 | /** |
||
| 884 | * Set the form mode. |
||
| 885 | * |
||
| 886 | * @param $mode |
||
| 887 | * @return $this |
||
| 888 | */ |
||
| 889 | public function setFormMode($mode) |
||
| 895 | |||
| 896 | /** |
||
| 897 | * Get a form value. |
||
| 898 | * |
||
| 899 | * @param $key |
||
| 900 | * @param null $default |
||
| 901 | * @return mixed |
||
| 902 | */ |
||
| 903 | public function getFormValue($key, $default = null) |
||
| 907 | |||
| 908 | /** |
||
| 909 | * Set a form value. |
||
| 910 | * |
||
| 911 | * @param $key |
||
| 912 | * @param $value |
||
| 913 | * @return $this |
||
| 914 | */ |
||
| 915 | public function setFormValue($key, $value) |
||
| 921 | |||
| 922 | /** |
||
| 923 | * Get the form values. |
||
| 924 | * |
||
| 925 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 926 | */ |
||
| 927 | public function getFormValues() |
||
| 931 | |||
| 932 | /** |
||
| 933 | * Reset the form. |
||
| 934 | * |
||
| 935 | * @return $this |
||
| 936 | */ |
||
| 937 | public function resetForm() |
||
| 945 | |||
| 946 | /** |
||
| 947 | * Get the form input. |
||
| 948 | * |
||
| 949 | * @return array |
||
| 950 | */ |
||
| 951 | public function getFormInput() |
||
| 957 | |||
| 958 | /** |
||
| 959 | * Get the form data. |
||
| 960 | * |
||
| 961 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 962 | */ |
||
| 963 | public function getFormData() |
||
| 967 | |||
| 968 | /** |
||
| 969 | * Add form data. |
||
| 970 | * |
||
| 971 | * @param $key |
||
| 972 | * @param $value |
||
| 973 | * @return $this |
||
| 974 | */ |
||
| 975 | public function addFormData($key, $value) |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Ge the form response. |
||
| 984 | * |
||
| 985 | * @return null|Response |
||
| 986 | */ |
||
| 987 | public function getFormResponse() |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Set the form response. |
||
| 994 | * |
||
| 995 | * @param null|false|Response $response |
||
| 996 | * @return $this |
||
| 997 | */ |
||
| 998 | public function setFormResponse(Response $response) |
||
| 1004 | |||
| 1005 | /** |
||
| 1006 | * Get the form content. |
||
| 1007 | * |
||
| 1008 | * @return null|string |
||
| 1009 | */ |
||
| 1010 | public function getFormContent() |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * Get the form fields. |
||
| 1017 | * |
||
| 1018 | * @return Component\Field\FieldCollection |
||
| 1019 | */ |
||
| 1020 | public function getFormFields() |
||
| 1024 | |||
| 1025 | /** |
||
| 1026 | * Get the enabled form fields. |
||
| 1027 | * |
||
| 1028 | * @return Component\Field\FieldCollection |
||
| 1029 | */ |
||
| 1030 | public function getEnabledFormFields() |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * Get the form field. |
||
| 1037 | * |
||
| 1038 | * @param $fieldSlug |
||
| 1039 | * @return FieldType |
||
| 1040 | */ |
||
| 1041 | public function getFormField($fieldSlug) |
||
| 1045 | |||
| 1046 | /** |
||
| 1047 | * Get the form attribute map. |
||
| 1048 | * |
||
| 1049 | * @return FieldType |
||
| 1050 | */ |
||
| 1051 | public function getFormFieldFromAttribute($attribute) |
||
| 1062 | |||
| 1063 | /** |
||
| 1064 | * Disable a form field. |
||
| 1065 | * |
||
| 1066 | * @param $fieldSlug |
||
| 1067 | * @return FieldType |
||
| 1068 | */ |
||
| 1069 | public function disableFormField($fieldSlug) |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Get the form field slugs. |
||
| 1076 | * |
||
| 1077 | * @param null $prefix |
||
| 1078 | * @return array |
||
| 1079 | */ |
||
| 1080 | public function getFormFieldSlugs($prefix = null) |
||
| 1091 | |||
| 1092 | /** |
||
| 1093 | * Get the form field names. |
||
| 1094 | * |
||
| 1095 | * @return array |
||
| 1096 | */ |
||
| 1097 | public function getFormFieldNames() |
||
| 1103 | |||
| 1104 | /** |
||
| 1105 | * Add a form field. |
||
| 1106 | * |
||
| 1107 | * @param FieldType $field |
||
| 1108 | * @return $this |
||
| 1109 | */ |
||
| 1110 | public function addFormField(FieldType $field) |
||
| 1116 | |||
| 1117 | /** |
||
| 1118 | * Set the form errors. |
||
| 1119 | * |
||
| 1120 | * @param MessageBag $errors |
||
| 1121 | * @return $this |
||
| 1122 | */ |
||
| 1123 | public function setFormErrors(MessageBag $errors) |
||
| 1129 | |||
| 1130 | /** |
||
| 1131 | * Get the form errors. |
||
| 1132 | * |
||
| 1133 | * @return null|MessageBag |
||
| 1134 | */ |
||
| 1135 | public function getFormErrors() |
||
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Add an error to the form. |
||
| 1142 | * |
||
| 1143 | * @param $field |
||
| 1144 | * @param $message |
||
| 1145 | * @return $this |
||
| 1146 | */ |
||
| 1147 | public function addFormError($field, $message) |
||
| 1155 | |||
| 1156 | /** |
||
| 1157 | * Return whether the form has errors or not. |
||
| 1158 | * |
||
| 1159 | * @return bool |
||
| 1160 | */ |
||
| 1161 | public function hasFormErrors() |
||
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Return whether the field has an error or not. |
||
| 1170 | * |
||
| 1171 | * @param $fieldName |
||
| 1172 | * @return bool |
||
| 1173 | */ |
||
| 1174 | public function hasFormError($fieldName) |
||
| 1178 | |||
| 1179 | /** |
||
| 1180 | * Get the form actions. |
||
| 1181 | * |
||
| 1182 | * @return ActionCollection |
||
| 1183 | */ |
||
| 1184 | public function getFormActions() |
||
| 1188 | |||
| 1189 | /** |
||
| 1190 | * Get the active form action. |
||
| 1191 | * |
||
| 1192 | * @return null|ActionInterface |
||
| 1193 | */ |
||
| 1194 | public function getActiveFormAction() |
||
| 1206 | |||
| 1207 | /** |
||
| 1208 | * Add a form button. |
||
| 1209 | * |
||
| 1210 | * @param ButtonInterface $button |
||
| 1211 | * @return $this |
||
| 1212 | */ |
||
| 1213 | public function addFormButton(ButtonInterface $button) |
||
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Add a form section. |
||
| 1222 | * |
||
| 1223 | * @param $slug |
||
| 1224 | * @param array $section |
||
| 1225 | * @return $this |
||
| 1226 | */ |
||
| 1227 | public function addFormSection($slug, array $section) |
||
| 1233 | |||
| 1234 | /** |
||
| 1235 | * Set the form entry. |
||
| 1236 | * |
||
| 1237 | * @param $entry |
||
| 1238 | * @return $this |
||
| 1239 | */ |
||
| 1240 | public function setFormEntry($entry) |
||
| 1246 | |||
| 1247 | /** |
||
| 1248 | * Get a request value. |
||
| 1249 | * |
||
| 1250 | * @param $key |
||
| 1251 | * @param null $default |
||
| 1252 | * @return mixed |
||
| 1253 | */ |
||
| 1254 | public function getRequestValue($key, $default = null) |
||
| 1258 | |||
| 1259 | /** |
||
| 1260 | * Get a post value. |
||
| 1261 | * |
||
| 1262 | * @param $key |
||
| 1263 | * @param null $default |
||
| 1264 | * @return mixed |
||
| 1265 | */ |
||
| 1266 | public function getPostValue($key, $default = null) |
||
| 1270 | |||
| 1271 | /** |
||
| 1272 | * Return a post key flag. |
||
| 1273 | * |
||
| 1274 | * @param $key |
||
| 1275 | * @param null $default |
||
| 1276 | * @return mixed |
||
| 1277 | */ |
||
| 1278 | public function hasPostedInput($key) |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * Return whether any post data exists. |
||
| 1285 | * |
||
| 1286 | * @return bool |
||
| 1287 | */ |
||
| 1288 | public function hasPostData() |
||
| 1299 | |||
| 1300 | /** |
||
| 1301 | * Set the save flag. |
||
| 1302 | * |
||
| 1303 | * @param bool $save |
||
| 1304 | * @return $this |
||
| 1305 | */ |
||
| 1306 | public function setSave($save) |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Return the save flag. |
||
| 1315 | * |
||
| 1316 | * @return bool |
||
| 1317 | */ |
||
| 1318 | public function canSave() |
||
| 1322 | |||
| 1323 | /** |
||
| 1324 | * Set the read only flag. |
||
| 1325 | * |
||
| 1326 | * @param $readOnly |
||
| 1327 | * @return $this |
||
| 1328 | */ |
||
| 1329 | public function setReadOnly($readOnly) |
||
| 1335 | |||
| 1336 | /** |
||
| 1337 | * Return the read only flag. |
||
| 1338 | * |
||
| 1339 | * @return bool |
||
| 1340 | */ |
||
| 1341 | public function isReadOnly() |
||
| 1345 | } |
||
| 1346 |
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.