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 | * Store a reference to the parent form widget. |
||
| 19 | * |
||
| 20 | * @var FormInterface |
||
| 21 | */ |
||
| 22 | protected $form; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * The group's collection of fields. |
||
| 26 | * |
||
| 27 | * @var FormInputInterface[] |
||
| 28 | */ |
||
| 29 | private $inputs; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The input callback; called on every input. |
||
| 33 | * |
||
| 34 | * Callable signature: `function(FormInputInterface $input)` |
||
| 35 | * |
||
| 36 | * @var callable |
||
| 37 | */ |
||
| 38 | private $inputCallback; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Store the builder instance for the current class. |
||
| 42 | * |
||
| 43 | * @var FormInputBuilder |
||
| 44 | */ |
||
| 45 | protected $formInputBuilder; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * The L10N display mode. |
||
| 49 | * |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $l10nMode; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * The group's identifier. |
||
| 56 | * |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $ident; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * The group's priority. |
||
| 63 | * |
||
| 64 | * @var integer |
||
| 65 | */ |
||
| 66 | private $priority; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * The required Acl permissions fetch from form group. |
||
| 70 | * |
||
| 71 | * @var string[] $requiredAclPermissions |
||
| 72 | */ |
||
| 73 | private $requiredAclPermissions = []; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Class or Classes for tab form group. |
||
| 77 | * |
||
| 78 | * @var string|string[] |
||
| 79 | */ |
||
| 80 | private $tabCssClasses; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param FormInputBuilder $builder The builder, to create customized form input objects. |
||
| 84 | * @return FormGroupInterface Chainable |
||
| 85 | */ |
||
| 86 | protected function setFormInputBuilder(FormInputBuilder $builder) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param callable $cb The input callback. |
||
| 95 | * @return FormGroupInterface Chainable |
||
| 96 | */ |
||
| 97 | public function setInputCallback(callable $cb) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param FormInterface $form The parent form object. |
||
| 106 | * @return FormGroupInterface Chainable |
||
| 107 | */ |
||
| 108 | public function setForm(FormInterface $form) |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return FormInterface |
||
| 117 | */ |
||
| 118 | public function form() |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param string $mode The l10n mode. |
||
| 125 | * @return FormGroupInterface Chainable |
||
| 126 | */ |
||
| 127 | public function setL10nMode($mode) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return string |
||
| 136 | */ |
||
| 137 | public function l10nMode() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @param array $inputs The group inputs. |
||
| 144 | * @return FormGroupInterface Chainable |
||
| 145 | */ |
||
| 146 | public function setInputs(array $inputs) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param string $inputIdent The input identifier. |
||
| 158 | * @param array|FormInputInterface $input The input object or structure. |
||
| 159 | * @throws InvalidArgumentException If the ident argument is not a string or if the input is not valid. |
||
| 160 | * @return FormGroupInterface Chainable |
||
| 161 | */ |
||
| 162 | public function addInput($inputIdent, $input) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Form Input generator. |
||
| 188 | * |
||
| 189 | * @param callable $inputCallback Optional. Input callback. |
||
| 190 | * @return FormGroupInterface[]|Generator |
||
| 191 | */ |
||
| 192 | public function inputs(callable $inputCallback = null) |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Wether this group contains any inputs. |
||
| 212 | * |
||
| 213 | * @return boolean |
||
| 214 | */ |
||
| 215 | public function hasInputs() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * Get the number of inputs in this group. |
||
| 222 | * |
||
| 223 | * @return integer |
||
| 224 | */ |
||
| 225 | public function numInputs() |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Set the identifier of the group. |
||
| 232 | * |
||
| 233 | * @param string $ident The group identifier. |
||
| 234 | * @return self |
||
| 235 | */ |
||
| 236 | public function setIdent($ident) |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Retrieve the idenfitier of the group. |
||
| 245 | * |
||
| 246 | * @return string |
||
| 247 | */ |
||
| 248 | public function ident() |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Set the group's priority or sorting index. |
||
| 255 | * |
||
| 256 | * @param integer $priority An index, for sorting. |
||
| 257 | * @throws InvalidArgumentException If the priority is not an integer. |
||
| 258 | * @return self |
||
| 259 | */ |
||
| 260 | View Code Duplication | public function setPriority($priority) |
|
| 272 | |||
| 273 | /** |
||
| 274 | * Retrieve the group's priority or sorting index. |
||
| 275 | * |
||
| 276 | * @return integer |
||
| 277 | */ |
||
| 278 | public function priority() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @param string|\string[] $classes Class or Classes for tab form group. |
||
| 285 | * @return self |
||
| 286 | */ |
||
| 287 | public function setTabCssClasses($classes) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @return string|\string[] |
||
| 302 | */ |
||
| 303 | public function tabCssClasses() |
||
| 307 | } |
||
| 308 |
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.