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 |
||
5 | class GettextTranslator extends BaseTranslator implements TranslatorInterface |
||
6 | { |
||
7 | /** |
||
8 | * Constructor. Detects the current language using the environment variables. |
||
9 | * |
||
10 | * @param string $language |
||
11 | */ |
||
12 | public function __construct($language = null) |
||
28 | |||
29 | /** |
||
30 | * Define the current locale. |
||
31 | * |
||
32 | * @param string $language |
||
33 | * @param int|null $category |
||
34 | * |
||
35 | * @return self |
||
36 | */ |
||
37 | public function setLanguage($language, $category = null) |
||
48 | |||
49 | /** |
||
50 | * Loads a gettext domain. |
||
51 | * |
||
52 | * @param string $domain |
||
53 | * @param string $path |
||
54 | * @param bool $default |
||
55 | * |
||
56 | * @return self |
||
57 | */ |
||
58 | public function loadDomain($domain, $path = null, $default = true) |
||
69 | |||
70 | /** |
||
71 | * @see TranslatorInterface |
||
72 | * |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | public function gettext($original) |
||
79 | |||
80 | /** |
||
81 | * @see TranslatorInterface |
||
82 | * |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function ngettext($original, $plural, $value) |
||
89 | |||
90 | /** |
||
91 | * @see TranslatorInterface |
||
92 | * |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | public function dngettext($domain, $original, $plural, $value) |
||
99 | |||
100 | /** |
||
101 | * @see TranslatorInterface |
||
102 | * |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | View Code Duplication | public function npgettext($context, $original, $plural, $value) |
|
112 | |||
113 | /** |
||
114 | * @see TranslatorInterface |
||
115 | * |
||
116 | * {@inheritdoc} |
||
117 | */ |
||
118 | public function pgettext($context, $original) |
||
125 | |||
126 | /** |
||
127 | * @see TranslatorInterface |
||
128 | * |
||
129 | * {@inheritdoc} |
||
130 | */ |
||
131 | public function dgettext($domain, $original) |
||
135 | |||
136 | /** |
||
137 | * @see TranslatorInterface |
||
138 | * |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | public function dpgettext($domain, $context, $original) |
||
148 | |||
149 | /** |
||
150 | * @see TranslatorInterface |
||
151 | * |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | View Code Duplication | public function dnpgettext($domain, $context, $original, $plural, $value) |
|
161 | } |
||
162 |
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.