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 |
||
| 23 | class ExportManager |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var TranslationManager |
||
| 27 | */ |
||
| 28 | private $translationManager; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var YmlExport |
||
| 32 | */ |
||
| 33 | private $exporter; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var array |
||
| 37 | */ |
||
| 38 | private $locales; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var Translation[] |
||
| 42 | */ |
||
| 43 | private $refresh = []; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var YamlParser |
||
| 47 | */ |
||
| 48 | private $parser; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param ParameterBag $loadersContainer |
||
|
|
|||
| 52 | * @param TranslationManager $translationManager |
||
| 53 | * @param YmlExport $exporter |
||
| 54 | */ |
||
| 55 | public function __construct( |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function getLocales() |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @param array $locales |
||
| 74 | */ |
||
| 75 | public function setLocales($locales) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Exports translations from ES to files. |
||
| 82 | * |
||
| 83 | * @param array $domains To export. |
||
| 84 | * @param bool $force |
||
| 85 | */ |
||
| 86 | public function export($domains = [], $force = null) |
||
| 105 | |||
| 106 | |||
| 107 | /** |
||
| 108 | * Flatten multidimensional array and concatenating keys |
||
| 109 | * |
||
| 110 | * @param $array |
||
| 111 | * @return array |
||
| 112 | */ |
||
| 113 | View Code Duplication | private function flatten($array, $prefix = '') { |
|
| 125 | |||
| 126 | /** |
||
| 127 | * Get translations for export. |
||
| 128 | * |
||
| 129 | * @param array $domains To read from storage. |
||
| 130 | * @param bool $force Determines if the message status is relevant. |
||
| 131 | * |
||
| 132 | * @return array |
||
| 133 | */ |
||
| 134 | private function formExportList($domains, $force) |
||
| 167 | } |
||
| 168 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.