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 |
||
| 16 | class UserStatusFieldset extends Fieldset implements ViewPartialProviderInterface |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * View script for rendering |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $viewPartial = 'form/auth/status'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $statusOptions = []; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param String $partial |
||
| 33 | * |
||
| 34 | * @return $this |
||
| 35 | */ |
||
| 36 | public function setViewPartial($partial) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | public function getViewPartial() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return \Zend\Hydrator\HydratorInterface |
||
| 53 | */ |
||
| 54 | public function getHydrator() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param array $statusOptions |
||
| 66 | * @return UserStatusFieldset |
||
| 67 | */ |
||
| 68 | public function setStatusOptions(array $statusOptions) |
||
| 74 | |||
| 75 | View Code Duplication | public function init() |
|
| 96 | } |
||
| 97 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.