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 |
||
8 | class EventJsonDocumentLanguageAnalyzer extends ConfigurableJsonDocumentLanguageAnalyzer |
||
9 | { |
||
10 | public function __construct() |
||
20 | |||
21 | /** |
||
22 | * @todo Remove when full replay is done. |
||
23 | * @replay_i18n |
||
24 | * @see https://jira.uitdatabank.be/browse/III-2201 |
||
25 | * |
||
26 | * @param JsonDocument $jsonDocument |
||
27 | * @return \CultuurNet\UDB3\Language[] |
||
28 | */ |
||
29 | public function determineAvailableLanguages(JsonDocument $jsonDocument) |
||
34 | |||
35 | /** |
||
36 | * @todo Remove when full replay is done. |
||
37 | * @replay_i18n |
||
38 | * @see https://jira.uitdatabank.be/browse/III-2201 |
||
39 | * |
||
40 | * @param JsonDocument $jsonDocument |
||
41 | * @return \CultuurNet\UDB3\Language[] |
||
42 | */ |
||
43 | public function determineCompletedLanguages(JsonDocument $jsonDocument) |
||
48 | |||
49 | /** |
||
50 | * @todo Remove when full replay is done. |
||
51 | * @replay_i18n |
||
52 | * @see https://jira.uitdatabank.be/browse/III-2201 |
||
53 | * |
||
54 | * @param JsonDocument $jsonDocument |
||
55 | * @return JsonDocument |
||
56 | */ |
||
57 | private function polyFillMultilingualFields(JsonDocument $jsonDocument) |
||
70 | } |
||
71 |
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.