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 FallbackTranslator implements TranslatorInterface, TranslatorBagInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var TranslatorInterface|TranslatorBagInterface |
||
| 27 | */ |
||
| 28 | private $symfonyTranslator; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var Translator |
||
| 32 | */ |
||
| 33 | private $externalTranslator; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var string |
||
| 37 | */ |
||
| 38 | private $defaultLocale; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param string $defaultLocale |
||
| 42 | * @param TranslatorInterface $symfonyTranslator |
||
| 43 | * @param Translator $translatorService |
||
|
|
|||
| 44 | */ |
||
| 45 | 1 | public function __construct($defaultLocale, TranslatorInterface $symfonyTranslator, Translator $externalTranslator) |
|
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function trans($id, array $parameters = [], $domain = null, $locale = null) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * {@inheritdoc} |
||
| 80 | */ |
||
| 81 | View Code Duplication | public function transChoice($id, $number, array $parameters = [], $domain = null, $locale = null) |
|
| 103 | |||
| 104 | /** |
||
| 105 | * {@inheritdoc} |
||
| 106 | */ |
||
| 107 | public function setLocale($locale) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * {@inheritdoc} |
||
| 114 | */ |
||
| 115 | public function getLocale() |
||
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritdoc} |
||
| 122 | */ |
||
| 123 | public function getCatalogue($locale = null) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Passes through all unknown calls onto the translator object. |
||
| 130 | */ |
||
| 131 | public function __call($method, $args) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @param string $orgString This is the string in the default locale. It has the values of $parameters in the string already. |
||
| 138 | * @param string $locale you wan to translate to. |
||
| 139 | * @param array $parameters |
||
| 140 | * |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | 1 | private function translateWithSubstitutedParameters($orgString, $locale, array $parameters) |
|
| 161 | } |
||
| 162 |
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.