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 |
||
37 | View Code Duplication | class ProductIntRepository extends AbstractFinderRepository implements ProductIntRepositoryInterface |
|
|
|||
38 | { |
||
39 | |||
40 | /** |
||
41 | * Initializes the repository's prepared statements. |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | public function init() |
||
52 | |||
53 | /** |
||
54 | * Return's the primary key name of the entity. |
||
55 | * |
||
56 | * @return string The name of the entity's primary key |
||
57 | */ |
||
58 | public function getPrimaryKeyName() |
||
62 | |||
63 | /** |
||
64 | * Return's the finder's entity name. |
||
65 | * |
||
66 | * @return string The finder's entity name |
||
67 | */ |
||
68 | public function getEntityName() |
||
72 | |||
73 | /** |
||
74 | * Load's and return's the available integer attributes. |
||
75 | * |
||
76 | * @return array The integer attributes |
||
77 | */ |
||
78 | public function findAll() |
||
84 | |||
85 | /** |
||
86 | * Load's and return's the text attributes with the passed primary key/store ID. |
||
87 | * |
||
88 | * @param integer $pk The primary key of the attributes |
||
89 | * @param integer $storeId The store ID of the attributes |
||
90 | * |
||
91 | * @return array The text attributes |
||
92 | */ |
||
93 | public function findAllByPrimaryKeyAndStoreId($pk, $storeId) |
||
104 | } |
||
105 |
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.