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:
| 1 | <?php |
||
| 15 | trait FormGroupTrait |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var FormInputInterface[] $inputs |
||
| 19 | */ |
||
| 20 | private $inputs; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * In-memory copy of the parent form widget. |
||
| 24 | * @var FormInterface $form |
||
| 25 | */ |
||
| 26 | protected $form; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var FormInputBuilder $formInputBuilder |
||
| 30 | */ |
||
| 31 | protected $formInputBuilder; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The input callback; called on every input. |
||
| 35 | * Callable signature: `function(FormInputInterface $input)` |
||
| 36 | * |
||
| 37 | * @var callable $itemCallback |
||
| 38 | */ |
||
| 39 | private $inputCallback = null; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var boolean $active |
||
| 43 | */ |
||
| 44 | private $active = true; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var integer $priority |
||
| 48 | */ |
||
| 49 | private $priority; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string $l10nMode |
||
| 53 | */ |
||
| 54 | private $l10nMode; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param FormInputBuilder $builder The builder, to create customized form input objects. |
||
| 58 | * @return FormGroupInterface Chainable |
||
| 59 | */ |
||
| 60 | protected function setFormInputBuilder(FormInputBuilder $builder) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param callable $cb The input callback. |
||
| 68 | * @return FormGroupInterface Chainable |
||
| 69 | */ |
||
| 70 | public function setInputCallback(callable $cb) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param FormInterface $form The parent form object. |
||
| 78 | * @return FormGroupInterface Chainable |
||
| 79 | */ |
||
| 80 | public function setForm(FormInterface $form) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Allow the form to public. |
||
| 88 | * @return FormInterface |
||
| 89 | */ |
||
| 90 | public function form() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @param boolean $active The active flag. |
||
| 97 | * @return FormPropertyWidget Chainable |
||
| 98 | */ |
||
| 99 | public function setActive($active) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return boolean |
||
| 107 | */ |
||
| 108 | public function active() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param integer $priority The priority, for ordering purpose. |
||
| 115 | * @throws InvalidArgumentException If the priority argument is not a number. |
||
| 116 | * @return FormGroupInterface Chainable |
||
| 117 | */ |
||
| 118 | public function setPriority($priority) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @return integer |
||
| 132 | */ |
||
| 133 | public function priority() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param string $mode The l10n mode. |
||
| 140 | * @return FormGroupInterface Chainable |
||
| 141 | */ |
||
| 142 | public function setL10nMode($mode) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @return string |
||
| 150 | */ |
||
| 151 | public function l10nMode() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param array $inputs The group inputs. |
||
| 158 | * @return FormGroupInterface Chainable |
||
| 159 | */ |
||
| 160 | public function setInputs(array $inputs) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @param string $inputIdent The input identifier. |
||
| 171 | * @param array|FormInputInterface $input The input object or structure. |
||
| 172 | * @throws InvalidArgumentException If the ident argument is not a string or if the input is not valid. |
||
| 173 | * @return FormInterface Chainable |
||
| 174 | */ |
||
| 175 | public function addInput($inputIdent, $input) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Form Input generator. |
||
| 201 | * |
||
| 202 | * @param callable $inputCallback Optional. Input callback. |
||
| 203 | * @return FormGroupInterface[] |
||
| 204 | */ |
||
| 205 | View Code Duplication | public function inputs(callable $inputCallback = null) |
|
| 223 | |||
| 224 | /** |
||
| 225 | * Wether this group contains any inputs. |
||
| 226 | * |
||
| 227 | * @return boolean |
||
| 228 | */ |
||
| 229 | public function hasInputs() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Get the number of inputs in this group. |
||
| 236 | * |
||
| 237 | * @return integer |
||
| 238 | */ |
||
| 239 | public function numInputs() |
||
| 243 | } |
||
| 244 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.