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; |
||
| 18 | class FormCriteria |
||
| 19 | { |
||
| 20 | |||
| 21 | use FiresCallbacks; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The cache repository. |
||
| 25 | * |
||
| 26 | * @var Repository |
||
| 27 | */ |
||
| 28 | protected $cache; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * The form builder. |
||
| 32 | * |
||
| 33 | * @var FormBuilder |
||
| 34 | */ |
||
| 35 | protected $builder; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The request object. |
||
| 39 | * |
||
| 40 | * @var Request |
||
| 41 | */ |
||
| 42 | protected $request; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * The hydrator utility. |
||
| 46 | * |
||
| 47 | * @var Hydrator |
||
| 48 | */ |
||
| 49 | protected $hydrator; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * The service container. |
||
| 53 | * |
||
| 54 | * @var Container |
||
| 55 | */ |
||
| 56 | protected $container; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * The parameters. |
||
| 60 | * |
||
| 61 | * @var array |
||
| 62 | */ |
||
| 63 | protected $parameters = []; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Create a new FormCriteria instance. |
||
| 67 | * |
||
| 68 | * @param Repository $cache |
||
| 69 | * @param Request $request |
||
| 70 | * @param Hydrator $hydrator |
||
| 71 | * @param Container $container |
||
| 72 | * @param FormBuilder $builder |
||
| 73 | * @param array $parameters |
||
| 74 | */ |
||
| 75 | public function __construct( |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Get the form. |
||
| 97 | * |
||
| 98 | * @return FormPresenter |
||
| 99 | */ |
||
| 100 | public function get() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Build the builder. |
||
| 109 | * |
||
| 110 | * @return FormBuilder |
||
| 111 | */ |
||
| 112 | public function build() |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Set a parameter. |
||
| 166 | * |
||
| 167 | * @param $key |
||
| 168 | * @param $value |
||
| 169 | * @return $this |
||
| 170 | */ |
||
| 171 | public function setParameter($key, $value) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Get the builder. |
||
| 180 | * |
||
| 181 | * @return FormBuilder |
||
| 182 | */ |
||
| 183 | public function getBuilder() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Set the form builder. |
||
| 190 | * |
||
| 191 | * @param FormBuilder $builder |
||
| 192 | * @return $this |
||
| 193 | */ |
||
| 194 | public function setBuilder($builder) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Route through __get |
||
| 209 | * |
||
| 210 | * @param $name |
||
| 211 | * @return $this |
||
| 212 | */ |
||
| 213 | public function __get($name) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @param $name |
||
| 220 | * @param $arguments |
||
| 221 | * @return $this |
||
| 222 | */ |
||
| 223 | public function __call($name, $arguments) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Return the form. |
||
| 264 | * |
||
| 265 | * @return string |
||
| 266 | */ |
||
| 267 | public function __toString() |
||
| 271 | } |
||
| 272 |