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