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 | class ProductVarcharRepository extends AbstractFinderRepository implements ProductVarcharRepositoryInterface |
||
| 38 | { |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Initializes the repository's prepared statements. |
||
| 42 | * |
||
| 43 | * @return void |
||
| 44 | */ |
||
| 45 | public function init() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Return's the primary key name of the entity. |
||
| 57 | * |
||
| 58 | * @return string The name of the entity's primary key |
||
| 59 | */ |
||
| 60 | public function getPrimaryKeyName() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Return's the finder's entity name. |
||
| 67 | * |
||
| 68 | * @return string The finder's entity name |
||
| 69 | */ |
||
| 70 | public function getEntityName() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Load's and return's the available varchar attributes. |
||
| 77 | * |
||
| 78 | * @return array The varchar attributes |
||
| 79 | */ |
||
| 80 | public function findAll() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Load's and return's the varchar attributes with the passed primary key/store ID. |
||
| 91 | * |
||
| 92 | * @param integer $pk The primary key of the attributes |
||
| 93 | * @param integer $storeId The store ID of the attributes |
||
| 94 | * |
||
| 95 | * @return array The varchar attributes |
||
| 96 | */ |
||
| 97 | public function findAllByPrimaryKeyAndStoreId($pk, $storeId) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Load's and return's the varchar attributes with the passed params. |
||
| 111 | * |
||
| 112 | * @param integer $attributeCode The attribute code of the varchar attribute |
||
| 113 | * @param integer $entityTypeId The entity type ID of the varchar attribute |
||
| 114 | * @param integer $storeId The store ID of the varchar attribute |
||
| 115 | * |
||
| 116 | * @return array The varchar attributes |
||
| 117 | */ |
||
| 118 | View Code Duplication | public function findAllByAttributeCodeAndEntityTypeIdAndStoreId($attributeCode, $entityTypeId, $storeId) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Load's and return's the varchar attribute with the passed params. |
||
| 136 | * |
||
| 137 | * @param integer $attributeCode The attribute code of the varchar attribute |
||
| 138 | * @param integer $entityTypeId The entity type ID of the varchar attribute |
||
| 139 | * @param integer $storeId The store ID of the varchar attribute |
||
| 140 | * @param string $value The value of the varchar attribute |
||
| 141 | * |
||
| 142 | * @return array|null The varchar attribute |
||
| 143 | */ |
||
| 144 | View Code Duplication | public function findOneByAttributeCodeAndEntityTypeIdAndStoreIdAndValue($attributeCode, $entityTypeId, $storeId, $value) |
|
| 158 | } |
||
| 159 |
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.