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 |
||
| 34 | View Code Duplication | class EavAttributeGroupRepository extends AbstractRepository |
|
|
|
|||
| 35 | { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The prepared statement to load a specific attribute group. |
||
| 39 | * |
||
| 40 | * @var \PDOStatement |
||
| 41 | */ |
||
| 42 | protected $eavAttributeGroupStmt; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * The prepared statement to load an attribute group for a specific attribute set ID. |
||
| 46 | * |
||
| 47 | * @var \PDOStatement |
||
| 48 | */ |
||
| 49 | protected $eavAttributeGroupsByAttributeSetIdStmt; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Initializes the repository's prepared statements. |
||
| 53 | * |
||
| 54 | * @return void |
||
| 55 | */ |
||
| 56 | public function init() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Return's the EAV attribute group with the passed ID. |
||
| 69 | * |
||
| 70 | * @param integer $id The EAV attribute group ID |
||
| 71 | * |
||
| 72 | * @return array The EAV attribute group |
||
| 73 | */ |
||
| 74 | public function load($id) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Return's the attribute groups for the passed attribute set ID, whereas the array |
||
| 84 | * is prepared with the attribute group names as keys. |
||
| 85 | * |
||
| 86 | * @param mixed $attributeSetId The EAV attribute set ID to return the attribute groups for |
||
| 87 | * |
||
| 88 | * @return array|boolean The EAV attribute groups for the passed attribute ID |
||
| 89 | */ |
||
| 90 | public function findAllByAttributeSetId($attributeSetId) |
||
| 107 | } |
||
| 108 |
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.