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 |
||
| 21 | abstract class AbstractEntityInitialiser |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @var ListEntriesHelper Helper service for managing list entries |
||
| 25 | */ |
||
| 26 | protected $listEntriesHelper; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * EntityInitialiser constructor. |
||
| 30 | * |
||
| 31 | * @param ListEntriesHelper $listEntriesHelper Helper service for managing list entries |
||
| 32 | */ |
||
| 33 | public function __construct(ListEntriesHelper $listEntriesHelper) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Initialises a given route instance. |
||
| 40 | * |
||
| 41 | * @param RouteEntity $entity The newly created entity instance |
||
| 42 | * |
||
| 43 | * @return RouteEntity The updated entity instance |
||
| 44 | */ |
||
| 45 | public function initRoute(RouteEntity $entity) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Returns the list entries helper. |
||
| 78 | * |
||
| 79 | * @return ListEntriesHelper |
||
| 80 | */ |
||
| 81 | public function getListEntriesHelper() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Sets the list entries helper. |
||
| 88 | * |
||
| 89 | * @param ListEntriesHelper $listEntriesHelper |
||
| 90 | * |
||
| 91 | * @return void |
||
| 92 | */ |
||
| 93 | public function setListEntriesHelper($listEntriesHelper) |
||
| 99 | |||
| 100 | } |
||
| 101 |
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.