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 |
||
| 24 | class DefaultProvider implements EmailDataProviderInterface |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var array |
||
| 28 | */ |
||
| 29 | protected $configResolver; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var \eZ\Publish\Core\Helper\TranslationHelper |
||
| 33 | */ |
||
| 34 | protected $translationHelper; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var \eZ\Publish\Core\Helper\FieldHelper |
||
| 38 | */ |
||
| 39 | protected $fieldHelper; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var \Twig\Environment |
||
| 43 | */ |
||
| 44 | protected $twig; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * EmailDataFactory constructor. |
||
| 48 | * |
||
| 49 | * @param array $config |
||
|
|
|||
| 50 | * @param \eZ\Publish\Core\Helper\TranslationHelper $translationHelper |
||
| 51 | * @param \eZ\Publish\Core\Helper\FieldHelper $fieldHelper |
||
| 52 | * @param \Twig\Environment $twig |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function __construct( |
|
| 66 | |||
| 67 | /** |
||
| 68 | * Factory method. |
||
| 69 | * |
||
| 70 | * @param InformationCollected $value |
||
| 71 | * |
||
| 72 | * @return EmailContent |
||
| 73 | */ |
||
| 74 | View Code Duplication | public function build(InformationCollected $value): EmailContent |
|
| 93 | |||
| 94 | public function provide(InformationCollected $value): Email |
||
| 98 | } |
||
| 99 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.