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; |
||
| 37 | class FormBuilder |
||
| 38 | { |
||
| 39 | |||
| 40 | use DispatchesJobs; |
||
| 41 | use FiresCallbacks; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The ajax flag. |
||
| 45 | * |
||
| 46 | * @var bool |
||
| 47 | */ |
||
| 48 | protected $ajax = false; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The form handler. |
||
| 52 | * |
||
| 53 | * @var null|string |
||
| 54 | */ |
||
| 55 | protected $handler = null; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The form validator. |
||
| 59 | * |
||
| 60 | * @var null|string |
||
| 61 | */ |
||
| 62 | protected $validator = null; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The form repository. |
||
| 66 | * |
||
| 67 | * @var null|FormRepositoryInterface |
||
| 68 | */ |
||
| 69 | protected $repository = null; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * The form model. |
||
| 73 | * |
||
| 74 | * @var null |
||
| 75 | */ |
||
| 76 | protected $model = null; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * The entry object. |
||
| 80 | * |
||
| 81 | * @var null|int |
||
| 82 | */ |
||
| 83 | protected $entry = null; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * The fields config. |
||
| 87 | * |
||
| 88 | * @var array|string |
||
| 89 | */ |
||
| 90 | protected $fields = []; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Fields to skip. |
||
| 94 | * |
||
| 95 | * @var array|string |
||
| 96 | */ |
||
| 97 | protected $skips = []; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * The actions config. |
||
| 101 | * |
||
| 102 | * @var array|string |
||
| 103 | */ |
||
| 104 | protected $actions = []; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * The buttons config. |
||
| 108 | * |
||
| 109 | * @var array|string |
||
| 110 | */ |
||
| 111 | protected $buttons = []; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The form options. |
||
| 115 | * |
||
| 116 | * @var array |
||
| 117 | */ |
||
| 118 | protected $options = []; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * The form sections. |
||
| 122 | * |
||
| 123 | * @var array |
||
| 124 | */ |
||
| 125 | protected $sections = []; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * The form assets. |
||
| 129 | * |
||
| 130 | * @var array |
||
| 131 | */ |
||
| 132 | protected $assets = []; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * The save flag. |
||
| 136 | * |
||
| 137 | * @var bool |
||
| 138 | */ |
||
| 139 | protected $save = true; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * The read only flag. |
||
| 143 | * |
||
| 144 | * @var bool |
||
| 145 | */ |
||
| 146 | protected $readOnly = false; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * The form object. |
||
| 150 | * |
||
| 151 | * @var Form |
||
| 152 | */ |
||
| 153 | protected $form; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Crate a new FormBuilder instance. |
||
| 157 | * |
||
| 158 | * @param Form $form |
||
| 159 | */ |
||
| 160 | public function __construct(Form $form) |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Build the form. |
||
| 167 | * |
||
| 168 | * @param null $entry |
||
| 169 | * @return $this |
||
| 170 | */ |
||
| 171 | public function build($entry = null) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Make the form. |
||
| 188 | * |
||
| 189 | * @param null $entry |
||
| 190 | * @return $this |
||
| 191 | */ |
||
| 192 | public function make($entry = null) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * Handle the form post. |
||
| 210 | * |
||
| 211 | * @param null $entry |
||
| 212 | * @throws \Exception |
||
| 213 | */ |
||
| 214 | public function handle($entry = null) |
||
| 223 | |||
| 224 | /** |
||
| 225 | * Trigger post operations |
||
| 226 | * for the form. |
||
| 227 | * |
||
| 228 | * @return $this |
||
| 229 | */ |
||
| 230 | public function post() |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Flash form information to be |
||
| 248 | * used in conjunction with redirect |
||
| 249 | * type responses (not self handling). |
||
| 250 | */ |
||
| 251 | public function flash() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Render the form. |
||
| 259 | * |
||
| 260 | * @param null $entry |
||
| 261 | * @return Response |
||
| 262 | */ |
||
| 263 | public function render($entry = null) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Fire field events. |
||
| 276 | * |
||
| 277 | * @param $trigger |
||
| 278 | * @param array $payload |
||
| 279 | */ |
||
| 280 | public function fireFieldEvents($trigger, array $payload = []) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Save the form. |
||
| 290 | */ |
||
| 291 | public function saveForm() |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Get the form object. |
||
| 298 | * |
||
| 299 | * @return Form |
||
| 300 | */ |
||
| 301 | public function getForm() |
||
| 305 | |||
| 306 | /** |
||
| 307 | * Get the form presenter. |
||
| 308 | * |
||
| 309 | * @return FormPresenter |
||
| 310 | */ |
||
| 311 | public function getFormPresenter() |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Get the ajax flag. |
||
| 318 | * |
||
| 319 | * @return bool |
||
| 320 | */ |
||
| 321 | public function isAjax() |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Set the ajax flag. |
||
| 328 | * |
||
| 329 | * @param $ajax |
||
| 330 | * @return $this |
||
| 331 | */ |
||
| 332 | public function setAjax($ajax) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Get the handler. |
||
| 341 | * |
||
| 342 | * @return null|string |
||
| 343 | */ |
||
| 344 | public function getHandler() |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Set the handler. |
||
| 351 | * |
||
| 352 | * @param $handler |
||
| 353 | * @return $this |
||
| 354 | */ |
||
| 355 | public function setHandler($handler) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Get the validator. |
||
| 364 | * |
||
| 365 | * @return null|string |
||
| 366 | */ |
||
| 367 | public function getValidator() |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Set the validator. |
||
| 374 | * |
||
| 375 | * @param $validator |
||
| 376 | * @return $this |
||
| 377 | */ |
||
| 378 | public function setValidator($validator) |
||
| 384 | |||
| 385 | /** |
||
| 386 | * Get the repository. |
||
| 387 | * |
||
| 388 | * @return FormRepositoryInterface|null |
||
| 389 | */ |
||
| 390 | public function getRepository() |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Set the form repository. |
||
| 397 | * |
||
| 398 | * @param FormRepositoryInterface $repository |
||
| 399 | * @return $this |
||
| 400 | */ |
||
| 401 | public function setRepository(FormRepositoryInterface $repository) |
||
| 407 | |||
| 408 | /** |
||
| 409 | * Set the form model. |
||
| 410 | * |
||
| 411 | * @param $model |
||
| 412 | * @return $this |
||
| 413 | */ |
||
| 414 | public function setModel($model) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * Get the form model. |
||
| 423 | * |
||
| 424 | * @return null |
||
| 425 | */ |
||
| 426 | public function getModel() |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Set the entry object. |
||
| 433 | * |
||
| 434 | * @param $entry |
||
| 435 | * @return $this |
||
| 436 | */ |
||
| 437 | public function setEntry($entry) |
||
| 443 | |||
| 444 | /** |
||
| 445 | * Get the entry object. |
||
| 446 | * |
||
| 447 | * @return null|EntryInterface|FieldInterface|mixed |
||
| 448 | */ |
||
| 449 | public function getEntry() |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Set the fields. |
||
| 456 | * |
||
| 457 | * @param $fields |
||
| 458 | * @return $this |
||
| 459 | */ |
||
| 460 | public function setFields($fields) |
||
| 466 | |||
| 467 | /** |
||
| 468 | * Get the fields. |
||
| 469 | * |
||
| 470 | * @return array |
||
| 471 | */ |
||
| 472 | public function getFields() |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Add a field. |
||
| 479 | * |
||
| 480 | * @param $field |
||
| 481 | */ |
||
| 482 | public function addField($field) |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Add fields. |
||
| 489 | * |
||
| 490 | * @param array $fields |
||
| 491 | */ |
||
| 492 | public function addFields(array $fields) |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Get the skipped fields. |
||
| 499 | * |
||
| 500 | * @return array |
||
| 501 | */ |
||
| 502 | public function getSkips() |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Set the skipped fields. |
||
| 509 | * |
||
| 510 | * @param $skips |
||
| 511 | * @return $this |
||
| 512 | */ |
||
| 513 | public function setSkips($skips) |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Add a skipped field. |
||
| 522 | * |
||
| 523 | * @param $fieldSlug |
||
| 524 | * @return $this |
||
| 525 | */ |
||
| 526 | public function skipField($fieldSlug) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Set the actions config. |
||
| 535 | * |
||
| 536 | * @param $actions |
||
| 537 | * @return $this |
||
| 538 | */ |
||
| 539 | public function setActions($actions) |
||
| 545 | |||
| 546 | /** |
||
| 547 | * Add an action. |
||
| 548 | * |
||
| 549 | * @param $slug |
||
| 550 | * @param array $definition |
||
| 551 | * @return $this |
||
| 552 | */ |
||
| 553 | public function addAction($slug, array $definition = []) |
||
| 563 | |||
| 564 | /** |
||
| 565 | * Get the actions config. |
||
| 566 | * |
||
| 567 | * @return array |
||
| 568 | */ |
||
| 569 | public function getActions() |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Set the buttons config. |
||
| 576 | * |
||
| 577 | * @param $buttons |
||
| 578 | * @return $this |
||
| 579 | */ |
||
| 580 | public function setButtons($buttons) |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Get the buttons config. |
||
| 589 | * |
||
| 590 | * @return array |
||
| 591 | */ |
||
| 592 | public function getButtons() |
||
| 596 | |||
| 597 | /** |
||
| 598 | * The the options. |
||
| 599 | * |
||
| 600 | * @return array |
||
| 601 | */ |
||
| 602 | public function getOptions() |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Set the options. |
||
| 609 | * |
||
| 610 | * @param array|string $options |
||
| 611 | * @return $this |
||
| 612 | */ |
||
| 613 | public function setOptions($options) |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Merge in options. |
||
| 622 | * |
||
| 623 | * @param array|string $options |
||
| 624 | * @return $this |
||
| 625 | */ |
||
| 626 | public function mergeOptions($options) |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Get the sections. |
||
| 635 | * |
||
| 636 | * @return array |
||
| 637 | */ |
||
| 638 | public function getSections() |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Set the sections. |
||
| 645 | * |
||
| 646 | * @param array|Closure $sections |
||
| 647 | * @return $this |
||
| 648 | */ |
||
| 649 | public function setSections($sections) |
||
| 655 | |||
| 656 | /** |
||
| 657 | * Add a section. |
||
| 658 | * |
||
| 659 | * @param $slug |
||
| 660 | * @param array $section |
||
| 661 | * @return $this |
||
| 662 | */ |
||
| 663 | public function addSection($slug, array $section) |
||
| 669 | |||
| 670 | /** |
||
| 671 | * Add a section tab. |
||
| 672 | * |
||
| 673 | * @param $section |
||
| 674 | * @param $slug |
||
| 675 | * @param array $tab |
||
| 676 | * @return $this |
||
| 677 | */ |
||
| 678 | public function addSectionTab($section, $slug, array $tab) |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Get an option value. |
||
| 687 | * |
||
| 688 | * @param $key |
||
| 689 | * @param null $default |
||
| 690 | * @return mixed |
||
| 691 | */ |
||
| 692 | public function getOption($key, $default = null) |
||
| 696 | |||
| 697 | /** |
||
| 698 | * Set an option value. |
||
| 699 | * |
||
| 700 | * @param $key |
||
| 701 | * @param $value |
||
| 702 | * @return $this |
||
| 703 | */ |
||
| 704 | public function setOption($key, $value) |
||
| 710 | |||
| 711 | /** |
||
| 712 | * Get the assets. |
||
| 713 | * |
||
| 714 | * @return array |
||
| 715 | */ |
||
| 716 | public function getAssets() |
||
| 720 | |||
| 721 | /** |
||
| 722 | * Set the assets. |
||
| 723 | * |
||
| 724 | * @param $assets |
||
| 725 | * @return $this |
||
| 726 | */ |
||
| 727 | public function setAssets($assets) |
||
| 733 | |||
| 734 | /** |
||
| 735 | * Add an asset. |
||
| 736 | * |
||
| 737 | * @param $collection |
||
| 738 | * @param $asset |
||
| 739 | * @return $this |
||
| 740 | */ |
||
| 741 | View Code Duplication | public function addAsset($collection, $asset) |
|
| 751 | |||
| 752 | /** |
||
| 753 | * Get the form's stream. |
||
| 754 | * |
||
| 755 | * @return StreamInterface|null |
||
| 756 | */ |
||
| 757 | public function getFormStream() |
||
| 761 | |||
| 762 | /** |
||
| 763 | * Get a form option value. |
||
| 764 | * |
||
| 765 | * @param $key |
||
| 766 | * @param null $default |
||
| 767 | * @return mixed |
||
| 768 | */ |
||
| 769 | public function getFormOption($key, $default = null) |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Set a form option value. |
||
| 776 | * |
||
| 777 | * @param $key |
||
| 778 | * @param $value |
||
| 779 | * @return $this |
||
| 780 | */ |
||
| 781 | public function setFormOption($key, $value) |
||
| 787 | |||
| 788 | /** |
||
| 789 | * Get the form options. |
||
| 790 | * |
||
| 791 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 792 | */ |
||
| 793 | public function getFormOptions() |
||
| 797 | |||
| 798 | /** |
||
| 799 | * Get the form model. |
||
| 800 | * |
||
| 801 | * @return \Anomaly\Streams\Platform\Entry\EntryModel|EloquentModel|null |
||
| 802 | */ |
||
| 803 | public function getFormModel() |
||
| 807 | |||
| 808 | /** |
||
| 809 | * Get the form entry. |
||
| 810 | * |
||
| 811 | * @return EloquentModel|EntryInterface|FieldInterface|AssignmentInterface |
||
| 812 | */ |
||
| 813 | public function getFormEntry() |
||
| 817 | |||
| 818 | /** |
||
| 819 | * Return the form entry's ID. |
||
| 820 | * |
||
| 821 | * @return int|mixed|null |
||
| 822 | */ |
||
| 823 | public function getFormEntryId() |
||
| 833 | |||
| 834 | /** |
||
| 835 | * Get the contextual entry ID. |
||
| 836 | * |
||
| 837 | * @return int|null |
||
| 838 | */ |
||
| 839 | public function getContextualId() |
||
| 843 | |||
| 844 | /** |
||
| 845 | * Get the form mode. |
||
| 846 | * |
||
| 847 | * @return null|string |
||
| 848 | */ |
||
| 849 | public function getFormMode() |
||
| 853 | |||
| 854 | /** |
||
| 855 | * Set the form mode. |
||
| 856 | * |
||
| 857 | * @param $mode |
||
| 858 | * @return $this |
||
| 859 | */ |
||
| 860 | public function setFormMode($mode) |
||
| 866 | |||
| 867 | /** |
||
| 868 | * Get a form value. |
||
| 869 | * |
||
| 870 | * @param $key |
||
| 871 | * @param null $default |
||
| 872 | * @return mixed |
||
| 873 | */ |
||
| 874 | public function getFormValue($key, $default = null) |
||
| 878 | |||
| 879 | /** |
||
| 880 | * Set a form value. |
||
| 881 | * |
||
| 882 | * @param $key |
||
| 883 | * @param $value |
||
| 884 | * @return $this |
||
| 885 | */ |
||
| 886 | public function setFormValue($key, $value) |
||
| 892 | |||
| 893 | /** |
||
| 894 | * Get the form values. |
||
| 895 | * |
||
| 896 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 897 | */ |
||
| 898 | public function getFormValues() |
||
| 902 | |||
| 903 | /** |
||
| 904 | * Reset the form. |
||
| 905 | * |
||
| 906 | * @return $this |
||
| 907 | */ |
||
| 908 | public function resetForm() |
||
| 916 | |||
| 917 | /** |
||
| 918 | * Get the form input. |
||
| 919 | * |
||
| 920 | * @return array |
||
| 921 | */ |
||
| 922 | public function getFormInput() |
||
| 928 | |||
| 929 | /** |
||
| 930 | * Get the form data. |
||
| 931 | * |
||
| 932 | * @return \Anomaly\Streams\Platform\Support\Collection |
||
| 933 | */ |
||
| 934 | public function getFormData() |
||
| 938 | |||
| 939 | /** |
||
| 940 | * Ge the form response. |
||
| 941 | * |
||
| 942 | * @return null|Response |
||
| 943 | */ |
||
| 944 | public function getFormResponse() |
||
| 948 | |||
| 949 | /** |
||
| 950 | * Set the form response. |
||
| 951 | * |
||
| 952 | * @param null|false|Response $response |
||
| 953 | * @return $this |
||
| 954 | */ |
||
| 955 | public function setFormResponse(Response $response) |
||
| 961 | |||
| 962 | /** |
||
| 963 | * Get the form content. |
||
| 964 | * |
||
| 965 | * @return null|string |
||
| 966 | */ |
||
| 967 | public function getFormContent() |
||
| 971 | |||
| 972 | /** |
||
| 973 | * Get the form fields. |
||
| 974 | * |
||
| 975 | * @return Component\Field\FieldCollection |
||
| 976 | */ |
||
| 977 | public function getFormFields() |
||
| 981 | |||
| 982 | /** |
||
| 983 | * Get the enabled form fields. |
||
| 984 | * |
||
| 985 | * @return Component\Field\FieldCollection |
||
| 986 | */ |
||
| 987 | public function getEnabledFormFields() |
||
| 991 | |||
| 992 | /** |
||
| 993 | * Get the form field. |
||
| 994 | * |
||
| 995 | * @param $fieldSlug |
||
| 996 | * @return FieldType |
||
| 997 | */ |
||
| 998 | public function getFormField($fieldSlug) |
||
| 1002 | |||
| 1003 | /** |
||
| 1004 | * Get the form attribute map. |
||
| 1005 | * |
||
| 1006 | * @return FieldType |
||
| 1007 | */ |
||
| 1008 | public function getFormFieldFromAttribute($attribute) |
||
| 1019 | |||
| 1020 | /** |
||
| 1021 | * Disable a form field. |
||
| 1022 | * |
||
| 1023 | * @param $fieldSlug |
||
| 1024 | * @return FieldType |
||
| 1025 | */ |
||
| 1026 | public function disableFormField($fieldSlug) |
||
| 1030 | |||
| 1031 | /** |
||
| 1032 | * Get the form field slugs. |
||
| 1033 | * |
||
| 1034 | * @param null $prefix |
||
| 1035 | * @return array |
||
| 1036 | */ |
||
| 1037 | public function getFormFieldSlugs($prefix = null) |
||
| 1048 | |||
| 1049 | /** |
||
| 1050 | * Get the form field names. |
||
| 1051 | * |
||
| 1052 | * @return array |
||
| 1053 | */ |
||
| 1054 | public function getFormFieldNames() |
||
| 1060 | |||
| 1061 | /** |
||
| 1062 | * Add a form field. |
||
| 1063 | * |
||
| 1064 | * @param FieldType $field |
||
| 1065 | * @return $this |
||
| 1066 | */ |
||
| 1067 | public function addFormField(FieldType $field) |
||
| 1073 | |||
| 1074 | /** |
||
| 1075 | * Set the form errors. |
||
| 1076 | * |
||
| 1077 | * @param MessageBag $errors |
||
| 1078 | * @return $this |
||
| 1079 | */ |
||
| 1080 | public function setFormErrors(MessageBag $errors) |
||
| 1086 | |||
| 1087 | /** |
||
| 1088 | * Get the form errors. |
||
| 1089 | * |
||
| 1090 | * @return null|MessageBag |
||
| 1091 | */ |
||
| 1092 | public function getFormErrors() |
||
| 1096 | |||
| 1097 | /** |
||
| 1098 | * Add an error to the form. |
||
| 1099 | * |
||
| 1100 | * @param $field |
||
| 1101 | * @param $message |
||
| 1102 | * @return $this |
||
| 1103 | */ |
||
| 1104 | public function addFormError($field, $message) |
||
| 1112 | |||
| 1113 | /** |
||
| 1114 | * Return whether the form has errors or not. |
||
| 1115 | * |
||
| 1116 | * @return bool |
||
| 1117 | */ |
||
| 1118 | public function hasFormErrors() |
||
| 1124 | |||
| 1125 | /** |
||
| 1126 | * Return whether the field has an error or not. |
||
| 1127 | * |
||
| 1128 | * @param $fieldName |
||
| 1129 | * @return bool |
||
| 1130 | */ |
||
| 1131 | public function hasFormError($fieldName) |
||
| 1135 | |||
| 1136 | /** |
||
| 1137 | * Get the form actions. |
||
| 1138 | * |
||
| 1139 | * @return ActionCollection |
||
| 1140 | */ |
||
| 1141 | public function getFormActions() |
||
| 1145 | |||
| 1146 | /** |
||
| 1147 | * Add a form button. |
||
| 1148 | * |
||
| 1149 | * @param ButtonInterface $button |
||
| 1150 | * @return $this |
||
| 1151 | */ |
||
| 1152 | public function addFormButton(ButtonInterface $button) |
||
| 1158 | |||
| 1159 | /** |
||
| 1160 | * Add a form section. |
||
| 1161 | * |
||
| 1162 | * @param $slug |
||
| 1163 | * @param array $section |
||
| 1164 | * @return $this |
||
| 1165 | */ |
||
| 1166 | public function addFormSection($slug, array $section) |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * Set the form entry. |
||
| 1175 | * |
||
| 1176 | * @param $entry |
||
| 1177 | * @return $this |
||
| 1178 | */ |
||
| 1179 | public function setFormEntry($entry) |
||
| 1185 | |||
| 1186 | /** |
||
| 1187 | * Get a request value. |
||
| 1188 | * |
||
| 1189 | * @param $key |
||
| 1190 | * @param null $default |
||
| 1191 | * @return mixed |
||
| 1192 | */ |
||
| 1193 | public function getRequestValue($key, $default = null) |
||
| 1197 | |||
| 1198 | /** |
||
| 1199 | * Get a post value. |
||
| 1200 | * |
||
| 1201 | * @param $key |
||
| 1202 | * @param null $default |
||
| 1203 | * @return mixed |
||
| 1204 | */ |
||
| 1205 | public function getPostValue($key, $default = null) |
||
| 1209 | |||
| 1210 | /** |
||
| 1211 | * Return a post key flag. |
||
| 1212 | * |
||
| 1213 | * @param $key |
||
| 1214 | * @param null $default |
||
| 1215 | * @return mixed |
||
| 1216 | */ |
||
| 1217 | public function hasPostedInput($key) |
||
| 1221 | |||
| 1222 | /** |
||
| 1223 | * Return whether any post data exists. |
||
| 1224 | * |
||
| 1225 | * @return bool |
||
| 1226 | */ |
||
| 1227 | public function hasPostData() |
||
| 1238 | |||
| 1239 | /** |
||
| 1240 | * Set the save flag. |
||
| 1241 | * |
||
| 1242 | * @param bool $save |
||
| 1243 | * @return $this |
||
| 1244 | */ |
||
| 1245 | public function setSave($save) |
||
| 1251 | |||
| 1252 | /** |
||
| 1253 | * Return the save flag. |
||
| 1254 | * |
||
| 1255 | * @return bool |
||
| 1256 | */ |
||
| 1257 | public function canSave() |
||
| 1261 | |||
| 1262 | /** |
||
| 1263 | * Set the read only flag. |
||
| 1264 | * |
||
| 1265 | * @param $readOnly |
||
| 1266 | * @return $this |
||
| 1267 | */ |
||
| 1268 | public function setReadOnly($readOnly) |
||
| 1274 | |||
| 1275 | /** |
||
| 1276 | * Return the read only flag. |
||
| 1277 | * |
||
| 1278 | * @return bool |
||
| 1279 | */ |
||
| 1280 | public function isReadOnly() |
||
| 1284 | } |
||
| 1285 |
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.