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 |
||
| 9 | View Code Duplication | class OkapiSearchSetsRepository |
|
|
|
|||
| 10 | { |
||
| 11 | const TABLE = 'okapi_search_sets'; |
||
| 12 | |||
| 13 | /** @var Connection */ |
||
| 14 | private $connection; |
||
| 15 | |||
| 16 | public function __construct(Connection $connection) |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @return OkapiSearchSetsEntity[] |
||
| 23 | */ |
||
| 24 | public function fetchAll() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param array $where |
||
| 48 | * @return OkapiSearchSetsEntity |
||
| 49 | */ |
||
| 50 | public function fetchOneBy(array $where = []) |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param array $where |
||
| 76 | * @return OkapiSearchSetsEntity[] |
||
| 77 | */ |
||
| 78 | public function fetchBy(array $where = []) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param OkapiSearchSetsEntity $entity |
||
| 109 | * @return OkapiSearchSetsEntity |
||
| 110 | */ |
||
| 111 | public function create(OkapiSearchSetsEntity $entity) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param OkapiSearchSetsEntity $entity |
||
| 131 | * @return OkapiSearchSetsEntity |
||
| 132 | */ |
||
| 133 | public function update(OkapiSearchSetsEntity $entity) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param OkapiSearchSetsEntity $entity |
||
| 152 | * @return OkapiSearchSetsEntity |
||
| 153 | */ |
||
| 154 | public function remove(OkapiSearchSetsEntity $entity) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param OkapiSearchSetsEntity $entity |
||
| 172 | * @return [] |
||
| 173 | */ |
||
| 174 | public function getDatabaseArrayFromEntity(OkapiSearchSetsEntity $entity) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @param array $data |
||
| 186 | * @return OkapiSearchSetsEntity |
||
| 187 | */ |
||
| 188 | public function getEntityFromDatabaseArray(array $data) |
||
| 198 | } |
||
| 199 |
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.