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 namespace Anomaly\Streams\Platform\Ui\Form; |
||
| 17 | class FormCriteria |
||
| 18 | { |
||
| 19 | |||
| 20 | use FiresCallbacks; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * The cache repository. |
||
| 24 | * |
||
| 25 | * @var Repository |
||
| 26 | */ |
||
| 27 | protected $cache; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The form builder. |
||
| 31 | * |
||
| 32 | * @var FormBuilder |
||
| 33 | */ |
||
| 34 | protected $builder; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The request object. |
||
| 38 | * |
||
| 39 | * @var Request |
||
| 40 | */ |
||
| 41 | protected $request; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The hydrator utility. |
||
| 45 | * |
||
| 46 | * @var Hydrator |
||
| 47 | */ |
||
| 48 | protected $hydrator; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The parameters. |
||
| 52 | * |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | protected $parameters = []; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Create a new FormCriteria instance. |
||
| 59 | * |
||
| 60 | * @param Repository $cache |
||
| 61 | * @param Request $request |
||
| 62 | * @param Hydrator $hydrator |
||
| 63 | * @param FormBuilder $builder |
||
| 64 | * @param array $parameters |
||
| 65 | */ |
||
| 66 | public function __construct( |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Get the form. |
||
| 84 | * |
||
| 85 | * @return FormPresenter |
||
| 86 | */ |
||
| 87 | public function get() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Return the hydrated builder. |
||
| 96 | * |
||
| 97 | * @return FormBuilder |
||
| 98 | */ |
||
| 99 | public function builder() |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Build the builder. |
||
| 108 | */ |
||
| 109 | protected function build() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Set a parameter. |
||
| 138 | * |
||
| 139 | * @param $key |
||
| 140 | * @param $value |
||
| 141 | * @return $this |
||
| 142 | */ |
||
| 143 | public function setParameter($key, $value) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Get the builder. |
||
| 152 | * |
||
| 153 | * @return FormBuilder |
||
| 154 | */ |
||
| 155 | public function getBuilder() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Set the form builder. |
||
| 162 | * |
||
| 163 | * @param FormBuilder $builder |
||
| 164 | * @return $this |
||
| 165 | */ |
||
| 166 | public function setBuilder($builder) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Route through __get |
||
| 181 | * |
||
| 182 | * @param $name |
||
| 183 | * @return $this |
||
| 184 | */ |
||
| 185 | public function __get($name) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param $name |
||
| 192 | * @param $arguments |
||
| 193 | * @return $this |
||
| 194 | */ |
||
| 195 | public function __call($name, $arguments) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Return the form. |
||
| 236 | * |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | public function __toString() |
||
| 243 | } |
||
| 244 |