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 SingleArticleSelectionContentType extends SimpleContentType implements PreResolvableContentTypeInterface |
||
| 25 | { |
||
| 26 | use ArticleViewDocumentIdTrait; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var Manager |
||
| 30 | */ |
||
| 31 | private $searchManager; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var ReferenceStoreInterface |
||
| 35 | */ |
||
| 36 | private $referenceStore; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | private $articleDocumentClass; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @param Manager $searchManager |
||
| 45 | * @param ReferenceStoreInterface $referenceStore |
||
| 46 | * @param string $articleDocumentClass |
||
| 47 | */ |
||
| 48 | View Code Duplication | public function __construct( |
|
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritdoc} |
||
| 62 | */ |
||
| 63 | public function getContentData(PropertyInterface $property) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | public function preResolve(PropertyInterface $property) |
||
| 89 | } |
||
| 90 |
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.