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; |
||
| 35 | class FormBuilder |
||
| 36 | { |
||
| 37 | |||
| 38 | use DispatchesJobs; |
||
| 39 | use FiresCallbacks; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The ajax flag. |
||
| 43 | * |
||
| 44 | * @var bool |
||
| 45 | */ |
||
| 46 | protected $ajax = false; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The form handler. |
||
| 50 | * |
||
| 51 | * @var null|string |
||
| 52 | */ |
||
| 53 | protected $handler = null; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * The form validator. |
||
| 57 | * |
||
| 58 | * @var null|string |
||
| 59 | */ |
||
| 60 | protected $validator = null; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * The form repository. |
||
| 64 | * |
||
| 65 | * @var null|FormRepositoryInterface |
||
| 66 | */ |
||
| 67 | protected $repository = null; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * The form model. |
||
| 71 | * |
||
| 72 | * @var null |
||
| 73 | */ |
||
| 74 | protected $model = null; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * The entry object. |
||
| 78 | * |
||
| 79 | * @var null|int |
||
| 80 | */ |
||
| 81 | protected $entry = null; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * The fields config. |
||
| 85 | * |
||
| 86 | * @var array|string |
||
| 87 | */ |
||
| 88 | protected $fields = []; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Fields to skip. |
||
| 92 | * |
||
| 93 | * @var array|string |
||
| 94 | */ |
||
| 95 | protected $skips = []; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * The actions config. |
||
| 99 | * |
||
| 100 | * @var array|string |
||
| 101 | */ |
||
| 102 | protected $actions = []; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * The buttons config. |
||
| 106 | * |
||
| 107 | * @var array|string |
||
| 108 | */ |
||
| 109 | protected $buttons = []; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * The form options. |
||
| 113 | * |
||
| 114 | * @var array |
||
| 115 | */ |
||
| 116 | protected $options = []; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * The form sections. |
||
| 120 | * |
||
| 121 | * @var array |
||
| 122 | */ |
||
| 123 | protected $sections = []; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * The form assets. |
||
| 127 | * |
||
| 128 | * @var array |
||
| 129 | */ |
||
| 130 | protected $assets = []; |
||
| 131 | |||
| 132 | /** |
||
| 133 | * The save flag. |
||
| 134 | * |
||
| 135 | * @var bool |
||
| 136 | */ |
||
| 137 | protected $save = true; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * The read only flag. |
||
| 141 | * |
||
| 142 | * @var bool |
||
| 143 | */ |
||
| 144 | protected $readOnly = false; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * The form object. |
||
| 148 | * |
||
| 149 | * @var Form |
||
| 150 | */ |
||
| 151 | protected $form; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Crate a new FormBuilder instance. |
||
| 155 | * |
||
| 156 | * @param Form $form |
||
| 157 | */ |
||
| 158 | public function __construct(Form $form) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Build the form. |
||
| 165 | * |
||
| 166 | * @param null $entry |
||
| 167 | * @return $this |
||
| 168 | */ |
||
| 169 | public function build($entry = null) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Make the form. |
||
| 186 | * |
||
| 187 | * @param null $entry |
||
| 188 | * @return $this |
||
| 189 | */ |
||
| 190 | public function make($entry = null) |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Handle the form post. |
||
| 208 | * |
||
| 209 | * @param null $entry |
||
| 210 | * @throws \Exception |
||
| 211 | */ |
||
| 212 | public function handle($entry = null) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Trigger post operations |
||
| 224 | * for the form. |
||
| 225 | * |
||
| 226 | * @return $this |
||
| 227 | */ |
||
| 228 | public function post() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Render the form. |
||
| 246 | * |
||
| 247 | * @param null $entry |
||
| 248 | * @return Response |
||
| 249 | */ |
||
| 250 | public function render($entry = null) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Fire field events. |
||
| 263 | * |
||
| 264 | * @param $trigger |
||
| 265 | * @param array $payload |
||
| 266 | */ |
||
| 267 | public function fireFieldEvents($trigger, array $payload = []) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Save the form. |
||
| 277 | */ |
||
| 278 | public function saveForm() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Get the form object. |
||
| 285 | * |
||
| 286 | * @return Form |
||
| 287 | */ |
||
| 288 | public function getForm() |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Get the form presenter. |
||
| 295 | * |
||
| 296 | * @return FormPresenter |
||
| 297 | */ |
||
| 298 | public function getFormPresenter() |
||
| 302 | |||
| 303 | /** |
||
| 304 | * Get the ajax flag. |
||
| 305 | * |
||
| 306 | * @return bool |
||
| 307 | */ |
||
| 308 | public function isAjax() |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Set the ajax flag. |
||
| 315 | * |
||
| 316 | * @param $ajax |
||
| 317 | * @return $this |
||
| 318 | */ |
||
| 319 | public function setAjax($ajax) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Get the handler. |
||
| 328 | * |
||
| 329 | * @return null|string |
||
| 330 | */ |
||
| 331 | public function getHandler() |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Set the handler. |
||
| 338 | * |
||
| 339 | * @param $handler |
||
| 340 | * @return $this |
||
| 341 | */ |
||
| 342 | public function setHandler($handler) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Get the validator. |
||
| 351 | * |
||
| 352 | * @return null|string |
||
| 353 | */ |
||
| 354 | public function getValidator() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Set the validator. |
||
| 361 | * |
||
| 362 | * @param $validator |
||
| 363 | * @return $this |
||
| 364 | */ |
||
| 365 | public function setValidator($validator) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Get the repository. |
||
| 374 | * |
||
| 375 | * @return FormRepositoryInterface|null |
||
| 376 | */ |
||
| 377 | public function getRepository() |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Set the form repository. |
||
| 384 | * |
||
| 385 | * @param FormRepositoryInterface $repository |
||
| 386 | * @return $this |
||
| 387 | */ |
||
| 388 | public function setRepository(FormRepositoryInterface $repository) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Set the form model. |
||
| 397 | * |
||
| 398 | * @param $model |
||
| 399 | * @return $this |
||
| 400 | */ |
||
| 401 | public function setModel($model) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Get the form model. |
||
| 410 | * |
||
| 411 | * @return null |
||
| 412 | */ |
||
| 413 | public function getModel() |
||
| 417 | |||
| 418 | /** |
||
| 419 | * Set the entry object. |
||
| 420 | * |
||
| 421 | * @param $entry |
||
| 422 | * @return $this |
||
| 423 | */ |
||
| 424 | public function setEntry($entry) |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Get the entry object. |
||
| 433 | * |
||
| 434 | * @return null|EntryInterface|FieldInterface|mixed |
||
| 435 | */ |
||
| 436 | public function getEntry() |
||
| 440 | |||
| 441 | /** |
||
| 442 | * Set the fields. |
||
| 443 | * |
||
| 444 | * @param $fields |
||
| 445 | * @return $this |
||
| 446 | */ |
||
| 447 | public function setFields($fields) |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Get the fields. |
||
| 456 | * |
||
| 457 | * @return array |
||
| 458 | */ |
||
| 459 | public function getFields() |
||
| 463 | |||
| 464 | /** |
||
| 465 | * Add a field. |
||
| 466 | * |
||
| 467 | * @param $field |
||
| 468 | */ |
||
| 469 | public function addField($field) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Add fields. |
||
| 476 | * |
||
| 477 | * @param array $fields |
||
| 478 | */ |
||
| 479 | public function addFields(array $fields) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Get the skipped fields. |
||
| 486 | * |
||
| 487 | * @return array |
||
| 488 | */ |
||
| 489 | public function getSkips() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Set the skipped fields. |
||
| 496 | * |
||
| 497 | * @param $skips |
||
| 498 | * @return $this |
||
| 499 | */ |
||
| 500 | public function setSkips($skips) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Add a skipped field. |
||
| 509 | * |
||
| 510 | * @param $fieldSlug |
||
| 511 | * @return $this |
||
| 512 | */ |
||
| 513 | public function skipField($fieldSlug) |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Set the actions config. |
||
| 522 | * |
||
| 523 | * @param $actions |
||
| 524 | * @return $this |
||
| 525 | */ |
||
| 526 | public function setActions($actions) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Add an action. |
||
| 535 | * |
||
| 536 | * @param $slug |
||
| 537 | * @param array $definition |
||
| 538 | * @return $this |
||
| 539 | */ |
||
| 540 | public function addAction($slug, array $definition = []) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Get the actions config. |
||
| 553 | * |
||
| 554 | * @return array |
||
| 555 | */ |
||
| 556 | public function getActions() |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Set the buttons config. |
||
| 563 | * |
||
| 564 | * @param $buttons |
||
| 565 | * @return $this |
||
| 566 | */ |
||
| 567 | public function setButtons($buttons) |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Get the buttons config. |
||
| 576 | * |
||
| 577 | * @return array |
||
| 578 | */ |
||
| 579 | public function getButtons() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * The the options. |
||
| 586 | * |
||
| 587 | * @return array |
||
| 588 | */ |
||
| 589 | public function getOptions() |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Set the options. |
||
| 596 | * |
||
| 597 | * @param array|string $options |
||
| 598 | * @return $this |
||
| 599 | */ |
||
| 600 | public function setOptions($options) |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Merge in options. |
||
| 609 | * |
||
| 610 | * @param array|string $options |
||
| 611 | * @return $this |
||
| 612 | */ |
||
| 613 | public function mergeOptions($options) |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Get the sections. |
||
| 622 | * |
||
| 623 | * @return array |
||
| 624 | */ |
||
| 625 | public function getSections() |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Set the sections. |
||
| 632 | * |
||
| 633 | * @param array|Closure $sections |
||
| 634 | * @return $this |
||
| 635 | */ |
||
| 636 | public function setSections($sections) |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Add a section. |
||
| 645 | * |
||
| 646 | * @param $slug |
||
| 647 | * @param array $section |
||
| 648 | * @return $this |
||
| 649 | */ |
||
| 650 | public function addSection($slug, array $section) |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Add a section tab. |
||
| 659 | * |
||
| 660 | * @param $section |
||
| 661 | * @param $slug |
||
| 662 | * @param array $tab |
||
| 663 | * @return $this |
||
| 664 | */ |
||
| 665 | public function addSectionTab($section, $slug, array $tab) |
||
| 671 | |||
| 672 | /** |
||
| 673 | * Get an option value. |
||
| 674 | * |
||
| 675 | * @param $key |
||
| 676 | * @param null $default |
||
| 677 | * @return mixed |
||
| 678 | */ |
||
| 679 | public function getOption($key, $default = null) |
||
| 683 | |||
| 684 | /** |
||
| 685 | * Set an option value. |
||
| 686 | * |
||
| 687 | * @param $key |
||
| 688 | * @param $value |
||
| 689 | * @return $this |
||
| 690 | */ |
||
| 691 | public function setOption($key, $value) |
||
| 697 | |||
| 698 | /** |
||
| 699 | * Get the assets. |
||
| 700 | * |
||
| 701 | * @return array |
||
| 702 | */ |
||
| 703 | public function getAssets() |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Set the assets. |
||
| 710 | * |
||
| 711 | * @param $assets |
||
| 712 | * @return $this |
||
| 713 | */ |
||
| 714 | public function setAssets($assets) |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Add an asset. |
||
| 723 | * |
||
| 724 | * @param $collection |
||
| 725 | * @param $asset |
||
| 726 | * @return $this |
||
| 727 | */ |
||
| 728 | View Code Duplication | public function addAsset($collection, $asset) |
|
| 738 | |||
| 739 | /** |
||
| 740 | * Get the form's stream. |
||
| 741 | * |
||
| 742 | * @return StreamInterface|null |
||
| 743 | */ |
||
| 744 | public function getFormStream() |
||
| 748 | |||
| 749 | /** |
||
| 750 | * Get a form option value. |
||
| 751 | * |
||
| 752 | * @param $key |
||
| 753 | * @param null $default |
||
| 754 | * @return mixed |
||
| 755 | */ |
||
| 756 | public function getFormOption($key, $default = null) |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Set a form option value. |
||
| 763 | * |
||
| 764 | * @param $key |
||
| 765 | * @param $value |
||
| 766 | * @return $this |
||
| 767 | */ |
||
| 768 | public function setFormOption($key, $value) |
||
| 774 | |||
| 775 | /** |
||
| 776 | * Get the form options. |
||
| 777 | * |
||
| 778 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 779 | */ |
||
| 780 | public function getFormOptions() |
||
| 784 | |||
| 785 | /** |
||
| 786 | * Get the form model. |
||
| 787 | * |
||
| 788 | * @return \Anomaly\Streams\Platform\Entry\EntryModel|EloquentModel|null |
||
| 789 | */ |
||
| 790 | public function getFormModel() |
||
| 794 | |||
| 795 | /** |
||
| 796 | * Get the form entry. |
||
| 797 | * |
||
| 798 | * @return EloquentModel|EntryInterface|FieldInterface|AssignmentInterface |
||
| 799 | */ |
||
| 800 | public function getFormEntry() |
||
| 804 | |||
| 805 | /** |
||
| 806 | * Return the form entry's ID. |
||
| 807 | * |
||
| 808 | * @return int|mixed|null |
||
| 809 | */ |
||
| 810 | public function getFormEntryId() |
||
| 820 | |||
| 821 | /** |
||
| 822 | * Get the contextual entry ID. |
||
| 823 | * |
||
| 824 | * @return int|null |
||
| 825 | */ |
||
| 826 | public function getContextualId() |
||
| 830 | |||
| 831 | /** |
||
| 832 | * Get the form mode. |
||
| 833 | * |
||
| 834 | * @return null|string |
||
| 835 | */ |
||
| 836 | public function getFormMode() |
||
| 840 | |||
| 841 | /** |
||
| 842 | * Set the form mode. |
||
| 843 | * |
||
| 844 | * @param $mode |
||
| 845 | * @return $this |
||
| 846 | */ |
||
| 847 | public function setFormMode($mode) |
||
| 853 | |||
| 854 | /** |
||
| 855 | * Get a form value. |
||
| 856 | * |
||
| 857 | * @param $key |
||
| 858 | * @param null $default |
||
| 859 | * @return mixed |
||
| 860 | */ |
||
| 861 | public function getFormValue($key, $default = null) |
||
| 865 | |||
| 866 | /** |
||
| 867 | * Set a form value. |
||
| 868 | * |
||
| 869 | * @param $key |
||
| 870 | * @param $value |
||
| 871 | * @return $this |
||
| 872 | */ |
||
| 873 | public function setFormValue($key, $value) |
||
| 879 | |||
| 880 | /** |
||
| 881 | * Get the form values. |
||
| 882 | * |
||
| 883 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 884 | */ |
||
| 885 | public function getFormValues() |
||
| 889 | |||
| 890 | /** |
||
| 891 | * Reset the form. |
||
| 892 | * |
||
| 893 | * @return $this |
||
| 894 | */ |
||
| 895 | public function resetForm() |
||
| 903 | |||
| 904 | /** |
||
| 905 | * Get the form input. |
||
| 906 | * |
||
| 907 | * @return array |
||
| 908 | */ |
||
| 909 | public function getFormInput() |
||
| 915 | |||
| 916 | /** |
||
| 917 | * Get the form data. |
||
| 918 | * |
||
| 919 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 920 | */ |
||
| 921 | public function getFormData() |
||
| 925 | |||
| 926 | /** |
||
| 927 | * Ge the form response. |
||
| 928 | * |
||
| 929 | * @return null|Response |
||
| 930 | */ |
||
| 931 | public function getFormResponse() |
||
| 935 | |||
| 936 | /** |
||
| 937 | * Set the form response. |
||
| 938 | * |
||
| 939 | * @param null|false|Response $response |
||
| 940 | * @return $this |
||
| 941 | */ |
||
| 942 | public function setFormResponse(Response $response) |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Get the form content. |
||
| 951 | * |
||
| 952 | * @return null|string |
||
| 953 | */ |
||
| 954 | public function getFormContent() |
||
| 958 | |||
| 959 | /** |
||
| 960 | * Get the form fields. |
||
| 961 | * |
||
| 962 | * @return Component\Field\FieldCollection |
||
| 963 | */ |
||
| 964 | public function getFormFields() |
||
| 968 | |||
| 969 | /** |
||
| 970 | * Get the enabled form fields. |
||
| 971 | * |
||
| 972 | * @return Component\Field\FieldCollection |
||
| 973 | */ |
||
| 974 | public function getEnabledFormFields() |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Get the form field. |
||
| 981 | * |
||
| 982 | * @param $fieldSlug |
||
| 983 | * @return FieldType |
||
| 984 | */ |
||
| 985 | public function getFormField($fieldSlug) |
||
| 989 | |||
| 990 | /** |
||
| 991 | * Get the form attribute map. |
||
| 992 | * |
||
| 993 | * @return FieldType |
||
| 994 | */ |
||
| 995 | public function getFormFieldFromAttribute($attribute) |
||
| 1006 | |||
| 1007 | /** |
||
| 1008 | * Disable a form field. |
||
| 1009 | * |
||
| 1010 | * @param $fieldSlug |
||
| 1011 | * @return FieldType |
||
| 1012 | */ |
||
| 1013 | public function disableFormField($fieldSlug) |
||
| 1017 | |||
| 1018 | /** |
||
| 1019 | * Get the form field slugs. |
||
| 1020 | * |
||
| 1021 | * @param null $prefix |
||
| 1022 | * @return array |
||
| 1023 | */ |
||
| 1024 | public function getFormFieldSlugs($prefix = null) |
||
| 1035 | |||
| 1036 | /** |
||
| 1037 | * Get the form field names. |
||
| 1038 | * |
||
| 1039 | * @return array |
||
| 1040 | */ |
||
| 1041 | public function getFormFieldNames() |
||
| 1047 | |||
| 1048 | /** |
||
| 1049 | * Add a form field. |
||
| 1050 | * |
||
| 1051 | * @param FieldType $field |
||
| 1052 | * @return $this |
||
| 1053 | */ |
||
| 1054 | public function addFormField(FieldType $field) |
||
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Set the form errors. |
||
| 1063 | * |
||
| 1064 | * @param MessageBag $errors |
||
| 1065 | * @return $this |
||
| 1066 | */ |
||
| 1067 | public function setFormErrors(MessageBag $errors) |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Get the form errors. |
||
| 1076 | * |
||
| 1077 | * @return null|MessageBag |
||
| 1078 | */ |
||
| 1079 | public function getFormErrors() |
||
| 1083 | |||
| 1084 | /** |
||
| 1085 | * Add an error to the form. |
||
| 1086 | * |
||
| 1087 | * @param $field |
||
| 1088 | * @param $message |
||
| 1089 | * @return $this |
||
| 1090 | */ |
||
| 1091 | public function addFormError($field, $message) |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * Return whether the form has errors or not. |
||
| 1102 | * |
||
| 1103 | * @return bool |
||
| 1104 | */ |
||
| 1105 | public function hasFormErrors() |
||
| 1111 | |||
| 1112 | /** |
||
| 1113 | * Return whether the field has an error or not. |
||
| 1114 | * |
||
| 1115 | * @param $fieldName |
||
| 1116 | * @return bool |
||
| 1117 | */ |
||
| 1118 | public function hasFormError($fieldName) |
||
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Get the form actions. |
||
| 1125 | * |
||
| 1126 | * @return ActionCollection |
||
| 1127 | */ |
||
| 1128 | public function getFormActions() |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Add a form button. |
||
| 1135 | * |
||
| 1136 | * @param ButtonInterface $button |
||
| 1137 | * @return $this |
||
| 1138 | */ |
||
| 1139 | public function addFormButton(ButtonInterface $button) |
||
| 1145 | |||
| 1146 | /** |
||
| 1147 | * Add a form section. |
||
| 1148 | * |
||
| 1149 | * @param $slug |
||
| 1150 | * @param array $section |
||
| 1151 | * @return $this |
||
| 1152 | */ |
||
| 1153 | public function addFormSection($slug, array $section) |
||
| 1159 | |||
| 1160 | /** |
||
| 1161 | * Set the form entry. |
||
| 1162 | * |
||
| 1163 | * @param $entry |
||
| 1164 | * @return $this |
||
| 1165 | */ |
||
| 1166 | public function setFormEntry($entry) |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Get a request value. |
||
| 1175 | * |
||
| 1176 | * @param $key |
||
| 1177 | * @param null $default |
||
| 1178 | * @return mixed |
||
| 1179 | */ |
||
| 1180 | public function getRequestValue($key, $default = null) |
||
| 1184 | |||
| 1185 | /** |
||
| 1186 | * Get a post value. |
||
| 1187 | * |
||
| 1188 | * @param $key |
||
| 1189 | * @param null $default |
||
| 1190 | * @return mixed |
||
| 1191 | */ |
||
| 1192 | public function getPostValue($key, $default = null) |
||
| 1196 | |||
| 1197 | /** |
||
| 1198 | * Return a post key flag. |
||
| 1199 | * |
||
| 1200 | * @param $key |
||
| 1201 | * @param null $default |
||
| 1202 | * @return mixed |
||
| 1203 | */ |
||
| 1204 | public function hasPostedInput($key) |
||
| 1208 | |||
| 1209 | /** |
||
| 1210 | * Return whether any post data exists. |
||
| 1211 | * |
||
| 1212 | * @return bool |
||
| 1213 | */ |
||
| 1214 | public function hasPostData() |
||
| 1225 | |||
| 1226 | /** |
||
| 1227 | * Set the save flag. |
||
| 1228 | * |
||
| 1229 | * @param bool $save |
||
| 1230 | * @return $this |
||
| 1231 | */ |
||
| 1232 | public function setSave($save) |
||
| 1238 | |||
| 1239 | /** |
||
| 1240 | * Return the save flag. |
||
| 1241 | * |
||
| 1242 | * @return bool |
||
| 1243 | */ |
||
| 1244 | public function canSave() |
||
| 1248 | |||
| 1249 | /** |
||
| 1250 | * Set the read only flag. |
||
| 1251 | * |
||
| 1252 | * @param $readOnly |
||
| 1253 | * @return $this |
||
| 1254 | */ |
||
| 1255 | public function setReadOnly($readOnly) |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Return the read only flag. |
||
| 1264 | * |
||
| 1265 | * @return bool |
||
| 1266 | */ |
||
| 1267 | public function isReadOnly() |
||
| 1271 | } |
||
| 1272 |
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.