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 |
||
14 | trait MultiLanguageValueTrait |
||
15 | { |
||
16 | /** |
||
17 | * Holds the collection of names with languageCode keys. |
||
18 | * |
||
19 | * @var string[] |
||
20 | */ |
||
21 | protected $names; |
||
22 | |||
23 | /** |
||
24 | * Holds the collection of descriptions with languageCode keys. |
||
25 | * |
||
26 | * @var string[] |
||
27 | */ |
||
28 | protected $descriptions; |
||
29 | |||
30 | /** |
||
31 | * Main language. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $mainLanguageCode; |
||
36 | |||
37 | /** |
||
38 | * Prioritized languages provided by user when retrieving object using API. |
||
39 | * |
||
40 | * @internal |
||
41 | * @var string[] |
||
42 | */ |
||
43 | protected $prioritizedLanguageCodes = []; |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc}. |
||
47 | */ |
||
48 | public function getNames() |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc}. |
||
55 | */ |
||
56 | View Code Duplication | public function getName($languageCode = null) |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc}. |
||
73 | */ |
||
74 | public function getDescriptions() |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc}. |
||
81 | */ |
||
82 | View Code Duplication | public function getDescription($languageCode = null) |
|
96 | } |