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 | class EavAttributeOptionValueRepository extends AbstractRepository |
||
| 35 | { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The cache for the query results. |
||
| 39 | * |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | protected $cache = array(); |
||
| 43 | |||
| 44 | /** |
||
| 45 | * The prepared statement to load an existing EAV attribute option value by its attribute code, store ID and value. |
||
| 46 | * |
||
| 47 | * @var \PDOStatement |
||
| 48 | */ |
||
| 49 | protected $eavAttributeOptionValueByAttributeCodeAndStoreIdAndValueStmt; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * The prepared statement to load an existing EAV attribute option value by its option id and store ID |
||
| 53 | * |
||
| 54 | * @var \PDOStatement |
||
| 55 | */ |
||
| 56 | protected $eavAttributeOptionValueByOptionIdAndStoreIdStmt; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Initializes the repository's prepared statements. |
||
| 60 | * |
||
| 61 | * @return void |
||
| 62 | */ |
||
| 63 | public function init() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Load's and return's the EAV attribute option value with the passed code, store ID and value. |
||
| 80 | * |
||
| 81 | * @param string $attributeCode The code of the EAV attribute option to load |
||
| 82 | * @param integer $storeId The store ID of the attribute option to load |
||
| 83 | * @param string $value The value of the attribute option to load |
||
| 84 | * |
||
| 85 | * @return array The EAV attribute option value |
||
| 86 | */ |
||
| 87 | View Code Duplication | public function findOneByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value) |
|
| 101 | |||
| 102 | /** |
||
| 103 | * Load's and return's the EAV attribute option value with the passed option ID and store ID |
||
| 104 | * |
||
| 105 | * @param string $optionId The option ID of the attribute option |
||
| 106 | * @param integer $storeId The store ID of the attribute option to load |
||
| 107 | * |
||
| 108 | * @return array The EAV attribute option value |
||
| 109 | */ |
||
| 110 | View Code Duplication | public function findOneByOptionIdAndStoreId($optionId, $storeId) |
|
| 123 | } |
||
| 124 |
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.