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 |
||
36 | View Code Duplication | class ProductLinkAttributeVarcharRepository extends AbstractRepository implements ProductLinkAttributeVarcharRepositoryInterface |
|
|
|||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The prepared statement to load a existing product link attribute varchar attribute. |
||
41 | * |
||
42 | * @var \PDOStatement |
||
43 | */ |
||
44 | protected $productLinkAttributeVarcharStmt; |
||
45 | |||
46 | /** |
||
47 | * Initializes the repository's prepared statements. |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public function init() |
||
58 | |||
59 | /** |
||
60 | * Return's the product link attribute varchar value with the passed product link attribute/link ID. |
||
61 | * |
||
62 | * @param integer $productLinkAttributeId The product link attribute ID of the attributes |
||
63 | * @param integer $linkId The link ID of the attribute |
||
64 | * |
||
65 | * @return array The product link attribute varchar value |
||
66 | */ |
||
67 | public function findOneByProductLinkAttributeIdAndLinkId($productLinkAttributeId, $linkId) |
||
80 | } |
||
81 |
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.