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 PhpCode extends Extractor implements ExtractorInterface, ExtractorMultiInterface |
||
13 | { |
||
14 | public static $options = [ |
||
15 | // - false: to not extract comments |
||
16 | // - empty string: to extract all comments |
||
17 | // - non-empty string: to extract comments that start with that string |
||
18 | // - array with strings to extract comments format. |
||
19 | 'extractComments' => false, |
||
20 | |||
21 | 'constants' => [], |
||
22 | |||
23 | 'functions' => [ |
||
24 | 'gettext' => 'gettext', |
||
25 | '__' => 'gettext', |
||
26 | 'ngettext' => 'ngettext', |
||
27 | 'n__' => 'ngettext', |
||
28 | 'pgettext' => 'pgettext', |
||
29 | 'p__' => 'pgettext', |
||
30 | 'dgettext' => 'dgettext', |
||
31 | 'd__' => 'dgettext', |
||
32 | 'dngettext' => 'dngettext', |
||
33 | 'dn__' => 'dngettext', |
||
34 | 'dpgettext' => 'dpgettext', |
||
35 | 'dp__' => 'dpgettext', |
||
36 | 'npgettext' => 'npgettext', |
||
37 | 'np__' => 'npgettext', |
||
38 | 'dnpgettext' => 'dnpgettext', |
||
39 | 'dnp__' => 'dnpgettext', |
||
40 | 'noop' => 'noop', |
||
41 | 'noop__' => 'noop', |
||
42 | ], |
||
43 | ]; |
||
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | * @throws Exception |
||
48 | */ |
||
49 | public static function fromString($string, Translations $translations, array $options = []) |
||
53 | |||
54 | /** |
||
55 | * @inheritDoc |
||
56 | * @throws Exception |
||
57 | */ |
||
58 | public static function fromStringMultiple($string, array $translations, array $options = []) |
||
70 | |||
71 | /** |
||
72 | * @inheritDoc |
||
73 | */ |
||
74 | View Code Duplication | public static function fromFileMultiple($file, array $translations, array $options = []) |
|
81 | |||
82 | |||
83 | /** |
||
84 | * Decodes a T_CONSTANT_ENCAPSED_STRING string. |
||
85 | * |
||
86 | * @param string $value |
||
87 | * |
||
88 | * @return string |
||
89 | */ |
||
90 | public static function convertString($value) |
||
135 | |||
136 | /** |
||
137 | * @param $dec |
||
138 | * @return string|null |
||
139 | * @see http://php.net/manual/en/function.chr.php#118804 |
||
140 | */ |
||
141 | private static function unicodeChar($dec) |
||
167 | } |
||
168 |
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.