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 |
||
12 | class MemcachedMessagesFrontendCatalogue implements MessagesFrontendCatalogueInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | private $preparedTranslations = array(); |
||
18 | |||
19 | /** |
||
20 | * @var UberMemcached |
||
21 | */ |
||
22 | private $memcached; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $supportedLocales; |
||
28 | |||
29 | /** |
||
30 | * @param UberMemcached $memcached |
||
31 | * @param $supportedLocales |
||
32 | */ |
||
33 | public function __construct(UberMemcached $memcached, $supportedLocales) |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | public function prepareTranslations($domain, $keyYml, $message, $locale) |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | public function buildByLocale($locale) |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | View Code Duplication | public function buildByDomain($domain) |
|
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | View Code Duplication | public function buildByKey($keyYml) |
|
123 | |||
124 | /** |
||
125 | * {@inheritdoc} |
||
126 | */ |
||
127 | View Code Duplication | public function buildByText($text) |
|
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | View Code Duplication | public function getAll() |
|
171 | |||
172 | /** |
||
173 | * Replace translation by given properties |
||
174 | * |
||
175 | * @param $_key - defined translation key |
||
176 | * @param $_locale - defined translation locale |
||
177 | * @param $_domain - defined translation domain |
||
178 | * @param $formLocale - changed translation locale |
||
179 | * @param $formDomain - changed translation domain |
||
180 | * @param $formMessage - changed translation message |
||
181 | */ |
||
182 | public function replace($_key, $_locale, $_domain, $formLocale, $formDomain, $formMessage) |
||
193 | } |
||
194 |
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.