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 EavAttributeOptionValueRepository extends AbstractRepository implements EavAttributeOptionValueRepositoryInterface |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * The cache adapter instance. |
||
42 | * |
||
43 | * @var \TechDivision\Import\Cache\CacheAdapterInterface |
||
44 | */ |
||
45 | protected $cacheAdapter; |
||
46 | |||
47 | /** |
||
48 | * The prepared statement to load the existing EAV attribute option values. |
||
49 | * |
||
50 | * @var \PDOStatement |
||
51 | */ |
||
52 | protected $eavAttributeOptionValuesStmt; |
||
53 | |||
54 | /** |
||
55 | * The prepared statement to load an existing EAV attribute option value by its option id and store ID |
||
56 | * |
||
57 | * @var \PDOStatement |
||
58 | */ |
||
59 | protected $eavAttributeOptionValueByOptionIdAndStoreIdStmt; |
||
60 | |||
61 | /** |
||
62 | * The prepared statement to load an existing EAV attribute option value by its attribute code, store ID and value. |
||
63 | * |
||
64 | * @var \PDOStatement |
||
65 | */ |
||
66 | protected $eavAttributeOptionValueByAttributeCodeAndStoreIdAndValueStmt; |
||
67 | |||
68 | /** |
||
69 | * The prepared statement to load an existing EAV attribute option value by its entity type ID, attribute code, store ID and value. |
||
70 | * |
||
71 | * @var \PDOStatement |
||
72 | */ |
||
73 | protected $eavAttributeOptionValueByEntityTypeIdAndAttributeCodeAndStoreIdAndValueStmt; |
||
74 | |||
75 | /** |
||
76 | * Initialize the repository with the passed connection and utility class name. |
||
77 | * . |
||
78 | * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection instance |
||
79 | * @param \TechDivision\Import\Repositories\SqlStatementRepositoryInterface $sqlStatementRepository The SQL repository instance |
||
80 | * @param \TechDivision\Import\Cache\CacheAdapterInterface $cacheAdapter The cache adapter instance |
||
81 | */ |
||
82 | public function __construct( |
||
94 | |||
95 | /** |
||
96 | * Initializes the repository's prepared statements. |
||
97 | * |
||
98 | * @return void |
||
99 | */ |
||
100 | View Code Duplication | public function init() |
|
119 | |||
120 | /** |
||
121 | * Return's the primary key name of the entity. |
||
122 | * |
||
123 | * @return string The name of the entity's primary key |
||
124 | */ |
||
125 | public function getPrimaryKeyName() |
||
129 | |||
130 | /** |
||
131 | * Returns the cache adapter instance used to warm the repository. |
||
132 | * |
||
133 | * @return \TechDivision\Import\Cache\CacheAdapterInterface The repository's cache adapter instance |
||
134 | */ |
||
135 | public function getCacheAdapter() |
||
139 | |||
140 | /** |
||
141 | * Load's and return's the available EAV attribute option values. |
||
142 | * |
||
143 | * @return array The EAV attribute option values |
||
144 | */ |
||
145 | public function findAll() |
||
152 | |||
153 | /** |
||
154 | * Load's and return's the EAV attribute option value with the passed option ID and store ID |
||
155 | * |
||
156 | * @param string $optionId The option ID of the attribute option |
||
157 | * @param integer $storeId The store ID of the attribute option to load |
||
158 | * |
||
159 | * @return array The EAV attribute option value |
||
160 | */ |
||
161 | public function findOneByOptionIdAndStoreId($optionId, $storeId) |
||
195 | |||
196 | /** |
||
197 | * Load's and return's the EAV attribute option value with the passed code, store ID and value. |
||
198 | * |
||
199 | * @param string $attributeCode The code of the EAV attribute option to load |
||
200 | * @param integer $storeId The store ID of the attribute option to load |
||
201 | * @param string $value The value of the attribute option to load |
||
202 | * |
||
203 | * @return array The EAV attribute option value |
||
204 | * @deprecated Since 2.0.2, because multiple attributes with the same attribute code, but differenct entity type code can be available |
||
205 | * @see \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface::findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndValue() |
||
206 | */ |
||
207 | View Code Duplication | public function findOneByAttributeCodeAndStoreIdAndValue($attributeCode, $storeId, $value) |
|
242 | |||
243 | /** |
||
244 | * Load's and return's the EAV attribute option value with the passed entity type ID, code, store ID and value. |
||
245 | * |
||
246 | * @param string $entityTypeId The entity type ID of the EAV attribute to load the option value for |
||
247 | * @param string $attributeCode The code of the EAV attribute option to load |
||
248 | * @param integer $storeId The store ID of the attribute option to load |
||
249 | * @param string $value The value of the attribute option to load |
||
250 | * |
||
251 | * @return array The EAV attribute option value |
||
252 | */ |
||
253 | View Code Duplication | public function findOneByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value) |
|
289 | } |
||
290 |
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.