Complex classes like AttributeBunchProcessor often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AttributeBunchProcessor, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
44 | class AttributeBunchProcessor implements AttributeBunchProcessorInterface |
||
45 | { |
||
46 | |||
47 | /** |
||
48 | * A connection to use. |
||
49 | * |
||
50 | * @var \TechDivision\Import\Connection\ConnectionInterface |
||
51 | */ |
||
52 | protected $connection; |
||
53 | |||
54 | /** |
||
55 | * The attribute repository instance. |
||
56 | * |
||
57 | * @var \TechDivision\Import\Attribute\Repositories\AttributeRepositoryInterface |
||
58 | */ |
||
59 | protected $attributeRepository; |
||
60 | |||
61 | /** |
||
62 | * The attribute label repository instance. |
||
63 | * |
||
64 | * @var \TechDivision\Import\Attribute\Repositories\AttributeLabelRepositoryInterface |
||
65 | */ |
||
66 | protected $attributeLabelRepository; |
||
67 | |||
68 | /** |
||
69 | * The attribute option repository instance. |
||
70 | * |
||
71 | * @var \TechDivision\Import\Attribute\Repositories\AttributeOptionRepositoryInterface |
||
72 | */ |
||
73 | protected $attributeOptionRepository; |
||
74 | |||
75 | /** |
||
76 | * The repository to access EAV attribute option values. |
||
77 | * |
||
78 | * @var \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface |
||
79 | */ |
||
80 | protected $eavAttributeOptionValueRepository; |
||
81 | |||
82 | /** |
||
83 | * The attribute option swatch repository instance. |
||
84 | * |
||
85 | * @var \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepositoryInterface |
||
86 | */ |
||
87 | protected $attributeOptionSwatchRepository; |
||
88 | |||
89 | /** |
||
90 | * The catalog attribute repository instance. |
||
91 | * |
||
92 | * @var \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepositoryInterface |
||
93 | */ |
||
94 | protected $catalogAttributeRepository; |
||
95 | |||
96 | /** |
||
97 | * The entity attribute repository instance. |
||
98 | * |
||
99 | * @var \TechDivision\Import\Attribute\Repositories\EntityAttributeRepositoryInterface |
||
100 | */ |
||
101 | protected $entityAttributeRepository; |
||
102 | |||
103 | /** |
||
104 | * The EAV entity type repository instance. |
||
105 | * |
||
106 | * @var \TechDivision\Import\Repositories\EavEntityTypeRepositoryInterface |
||
107 | */ |
||
108 | protected $entityTypeRepository; |
||
109 | |||
110 | /** |
||
111 | * The attribute action instance. |
||
112 | * |
||
113 | * @var \TechDivision\Import\Actions\ActionInterface |
||
114 | */ |
||
115 | protected $attributeAction; |
||
116 | |||
117 | /** |
||
118 | * The attribute label action instance. |
||
119 | * |
||
120 | * @var \TechDivision\Import\Actions\ActionInterface |
||
121 | */ |
||
122 | protected $attributeLabelAction; |
||
123 | |||
124 | /** |
||
125 | * The attribute option action instance. |
||
126 | * |
||
127 | * @var \TechDivision\Import\Actions\ActionInterface |
||
128 | */ |
||
129 | protected $attributeOptionAction; |
||
130 | |||
131 | /** |
||
132 | * The attribute option value action instance. |
||
133 | * |
||
134 | * @var \TechDivision\Import\Actions\ActionInterface |
||
135 | */ |
||
136 | protected $attributeOptionValueAction; |
||
137 | |||
138 | /** |
||
139 | * The attribute option swatch action instance. |
||
140 | * |
||
141 | * @var \TechDivision\Import\Actions\ActionInterface |
||
142 | */ |
||
143 | protected $attributeOptionSwatchAction; |
||
144 | |||
145 | /** |
||
146 | * The attribute action instance. |
||
147 | * |
||
148 | * @var \TechDivision\Import\Actions\ActionInterface |
||
149 | */ |
||
150 | protected $catalogAttributeAction; |
||
151 | |||
152 | /** |
||
153 | * The entity attribute action instance. |
||
154 | * |
||
155 | * @var \TechDivision\Import\Actions\ActionInterface |
||
156 | */ |
||
157 | protected $entityAttributeAction; |
||
158 | |||
159 | /** |
||
160 | * The raw entity loader instance. |
||
161 | * |
||
162 | * @var \TechDivision\Import\Loaders\LoaderInterface |
||
163 | */ |
||
164 | protected $rawEntityLoader; |
||
165 | |||
166 | /** |
||
167 | * Initialize the processor with the necessary assembler and repository instances. |
||
168 | * |
||
169 | * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection to use |
||
170 | * @param \TechDivision\Import\Attribute\Repositories\AttributeRepositoryInterface $attributeRepository The attribute repository instance |
||
171 | * @param \TechDivision\Import\Attribute\Repositories\AttributeLabelRepositoryInterface $attributeLabelRepository The attribute label repository instance |
||
172 | * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionRepositoryInterface $attributeOptionRepository The attribute repository instance |
||
173 | * @param \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface $eavAttributeOptionValueRepository The EAV attribute option value repository to use |
||
174 | * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepositoryInterface $attributeOptionSwatchRepository The attribute repository swatch instance |
||
175 | * @param \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepositoryInterface $catalogAttributeRepository The catalog attribute repository instance |
||
176 | * @param \TechDivision\Import\Attribute\Repositories\EntityAttributeRepositoryInterface $entityAttributeRepository The entity attribute repository instance |
||
177 | * @param \TechDivision\Import\Repositories\EavEntityTypeRepositoryInterface $entityTypeRepository The entity type repository instance |
||
178 | * @param \TechDivision\Import\Actions\ActionInterface $attributeAction The attribute action instance |
||
179 | * @param \TechDivision\Import\Actions\ActionInterface $attributeLabelAction The attribute label action instance |
||
180 | * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionAction The attribute option action instance |
||
181 | * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionValueAction The attribute option value action instance |
||
182 | * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionSwatchAction The attribute option swatch action instance |
||
183 | * @param \TechDivision\Import\Actions\ActionInterface $catalogAttributeAction The catalog attribute action instance |
||
184 | * @param \TechDivision\Import\Actions\ActionInterface $entityAttributeAction The entity attribute action instance |
||
185 | * @param \TechDivision\Import\Loaders\LoaderInterface $rawEntityLoader The raw entity loader instance |
||
186 | */ |
||
187 | public function __construct( |
||
224 | |||
225 | /** |
||
226 | * Set's the raw entity loader instance. |
||
227 | * |
||
228 | * @param \TechDivision\Import\Loaders\LoaderInterface $rawEntityLoader The raw entity loader instance to set |
||
229 | * |
||
230 | * @return void |
||
231 | */ |
||
232 | public function setRawEntityLoader(LoaderInterface $rawEntityLoader) |
||
236 | |||
237 | /** |
||
238 | * Return's the raw entity loader instance. |
||
239 | * |
||
240 | * @return \TechDivision\Import\Loaders\LoaderInterface The raw entity loader instance |
||
241 | */ |
||
242 | public function getRawEntityLoader() |
||
246 | |||
247 | /** |
||
248 | * Set's the passed connection. |
||
249 | * |
||
250 | * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection to set |
||
251 | * |
||
252 | * @return void |
||
253 | */ |
||
254 | public function setConnection(ConnectionInterface $connection) |
||
258 | |||
259 | /** |
||
260 | * Return's the connection. |
||
261 | * |
||
262 | * @return \TechDivision\Import\Connection\ConnectionInterface The connection instance |
||
263 | */ |
||
264 | public function getConnection() |
||
268 | |||
269 | /** |
||
270 | * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
||
271 | * object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
||
272 | * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
||
273 | * to autocommit mode. |
||
274 | * |
||
275 | * @return boolean Returns TRUE on success or FALSE on failure |
||
276 | * @link http://php.net/manual/en/pdo.begintransaction.php |
||
277 | */ |
||
278 | public function beginTransaction() |
||
282 | |||
283 | /** |
||
284 | * Commits a transaction, returning the database connection to autocommit mode until the next call to |
||
285 | * ProductProcessor::beginTransaction() starts a new transaction. |
||
286 | * |
||
287 | * @return boolean Returns TRUE on success or FALSE on failure |
||
288 | * @link http://php.net/manual/en/pdo.commit.php |
||
289 | */ |
||
290 | public function commit() |
||
294 | |||
295 | /** |
||
296 | * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
||
297 | * |
||
298 | * If the database was set to autocommit mode, this function will restore autocommit mode after it has |
||
299 | * rolled back the transaction. |
||
300 | * |
||
301 | * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
||
302 | * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
||
303 | * COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
||
304 | * |
||
305 | * @return boolean Returns TRUE on success or FALSE on failure |
||
306 | * @link http://php.net/manual/en/pdo.rollback.php |
||
307 | */ |
||
308 | public function rollBack() |
||
312 | |||
313 | /** |
||
314 | * Set's the attribute repository instance. |
||
315 | * |
||
316 | * @param \TechDivision\Import\Attribute\Repositories\AttributeRepositoryInterface $attributeRepository The attribute repository instance |
||
317 | * |
||
318 | * @return void |
||
319 | */ |
||
320 | public function setAttributeRepository(AttributeRepositoryInterface $attributeRepository) |
||
324 | |||
325 | /** |
||
326 | * Return's the attribute repository instance. |
||
327 | * |
||
328 | * @return \TechDivision\Import\Attribute\Repositories\AttributeRepositoryInterface The attribute repository instance |
||
329 | */ |
||
330 | public function getAttributeRepository() |
||
334 | |||
335 | /** |
||
336 | * Set's the attribute label repository instance. |
||
337 | * |
||
338 | * @param \TechDivision\Import\Attribute\Repositories\AttributeLabelRepositoryInterface $attributeLabelRepository The attribute label repository instance |
||
339 | * |
||
340 | * @return void |
||
341 | */ |
||
342 | public function setAttributeLabelRepository(AttributeLabelRepositoryInterface $attributeLabelRepository) |
||
346 | |||
347 | /** |
||
348 | * Return's the attribute label repository instance. |
||
349 | * |
||
350 | * @return \TechDivision\Import\Attribute\Repositories\AttributeLabelRepositoryInterface The attribute label repository instance |
||
351 | */ |
||
352 | public function getAttributeLabelRepository() |
||
356 | |||
357 | /** |
||
358 | * Set's the attribute option repository instance. |
||
359 | * |
||
360 | * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionRepositoryInterface $attributeOptionRepository The attribute option repository instance |
||
361 | * |
||
362 | * @return void |
||
363 | */ |
||
364 | public function setAttributeOptionRepository(AttributeOptionRepositoryInterface $attributeOptionRepository) |
||
368 | |||
369 | /** |
||
370 | * Return's the attribute option repository instance. |
||
371 | * |
||
372 | * @return \TechDivision\Import\Attribute\Repositories\AttributeOptionRepositoryInterface The attribute option repository instance |
||
373 | */ |
||
374 | public function getAttributeOptionRepository() |
||
378 | |||
379 | /** |
||
380 | * Set's the repository to access EAV attribute option values. |
||
381 | * |
||
382 | * @param \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface $eavAttributeOptionValueRepository The repository to access EAV attribute option values |
||
383 | * |
||
384 | * @return void |
||
385 | */ |
||
386 | public function setEavAttributeOptionValueRepository(EavAttributeOptionValueRepositoryInterface $eavAttributeOptionValueRepository) |
||
390 | |||
391 | /** |
||
392 | * Return's the repository to access EAV attribute option values. |
||
393 | * |
||
394 | * @return \TechDivision\Import\Repositories\EavAttributeOptionValueRepositoryInterface The repository instance |
||
395 | */ |
||
396 | public function getEavAttributeOptionValueRepository() |
||
400 | |||
401 | /** |
||
402 | * Set's the attribute option swatch repository instance. |
||
403 | * |
||
404 | * @param \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepositoryInterface $attributeOptionSwatchRepository The attribute option swatch repository instance |
||
405 | * |
||
406 | * @return void |
||
407 | */ |
||
408 | public function setAttributeOptionSwatchRepository(AttributeOptionSwatchRepositoryInterface $attributeOptionSwatchRepository) |
||
412 | |||
413 | /** |
||
414 | * Return's the attribute option swatch repository instance. |
||
415 | * |
||
416 | * @return \TechDivision\Import\Attribute\Repositories\AttributeOptionSwatchRepositoryInterface The attribute option swatch repository instance |
||
417 | */ |
||
418 | public function getAttributeOptionSwatchRepository() |
||
422 | |||
423 | /** |
||
424 | * Set's the catalog attribute repository instance. |
||
425 | * |
||
426 | * @param \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepositoryInterface $catalogAttributeRepository The catalog attribute repository instance |
||
427 | * |
||
428 | * @return void |
||
429 | */ |
||
430 | public function setCatalogAttributeRepository(CatalogAttributeRepositoryInterface $catalogAttributeRepository) |
||
434 | |||
435 | /** |
||
436 | * Return's the catalog attribute repository instance. |
||
437 | * |
||
438 | * @return \TechDivision\Import\Attribute\Repositories\CatalogAttributeRepositoryInterface The catalog attribute repository instance |
||
439 | */ |
||
440 | public function getCatalogAttributeRepository() |
||
444 | |||
445 | /** |
||
446 | * Set's the entity attribute repository instance. |
||
447 | * |
||
448 | * @param \TechDivision\Import\Attribute\Repositories\EntityAttributeRepositoryInterface $entityAttributeRepository The entity attribute repository instance |
||
449 | * |
||
450 | * @return void |
||
451 | */ |
||
452 | public function setEntityAttributeRepository(EntityAttributeRepositoryInterface $entityAttributeRepository) |
||
456 | |||
457 | /** |
||
458 | * Return's the entity attribute repository instance. |
||
459 | * |
||
460 | * @return \TechDivision\Import\Attribute\Repositories\EntityAttributeRepositoryInterface The entity attribute repository instance |
||
461 | */ |
||
462 | public function getEntityAttributeRepository() |
||
466 | |||
467 | /** |
||
468 | * Sets the EAV entity type repository. |
||
469 | * |
||
470 | * @param \TechDivision\Import\Repositories\EavEntityTypeRepositoryInterface $entitTypeRepository The repository instance |
||
471 | * |
||
472 | * @return void |
||
473 | */ |
||
474 | public function setEntityTypeRepository(EavEntityTypeRepositoryInterface $entitTypeRepository) |
||
478 | |||
479 | /** |
||
480 | * Returns the EAV entity type repository. |
||
481 | * |
||
482 | * @return \TechDivision\Import\Repositories\EavEntityTypeRepositoryInterface The repository instance |
||
483 | */ |
||
484 | public function getEntityTypeRepository() |
||
488 | |||
489 | /** |
||
490 | * Set's the attribute action instance. |
||
491 | * |
||
492 | * @param \TechDivision\Import\Actions\ActionInterface $attributeAction The attribute action instance |
||
493 | * |
||
494 | * @return void |
||
495 | */ |
||
496 | public function setAttributeAction(ActionInterface $attributeAction) |
||
500 | |||
501 | /** |
||
502 | * Return's the attribute action instance. |
||
503 | * |
||
504 | * @return \TechDivision\Import\Actions\ActionInterface The attribute action instance |
||
505 | */ |
||
506 | public function getAttributeAction() |
||
510 | |||
511 | /** |
||
512 | * Set's the attribute label action instance. |
||
513 | * |
||
514 | * @param \TechDivision\Import\Actions\ActionInterface $attributeLabelAction The attribute label action instance |
||
515 | * |
||
516 | * @return void |
||
517 | */ |
||
518 | public function setAttributeLabelAction(ActionInterface $attributeLabelAction) |
||
522 | |||
523 | /** |
||
524 | * Return's the attribute label action instance. |
||
525 | * |
||
526 | * @return \TechDivision\Import\Actions\ActionInterface The attribute label action instance |
||
527 | */ |
||
528 | public function getAttributeLabelAction() |
||
532 | |||
533 | /** |
||
534 | * Set's the attribute option action instance. |
||
535 | * |
||
536 | * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionAction The attribute option action instance |
||
537 | * |
||
538 | * @return void |
||
539 | */ |
||
540 | public function setAttributeOptionAction(ActionInterface $attributeOptionAction) |
||
544 | |||
545 | /** |
||
546 | * Return's the attribute option action instance. |
||
547 | * |
||
548 | * @return \TechDivision\Import\Actions\ActionInterface The attribute option action instance |
||
549 | */ |
||
550 | public function getAttributeOptionAction() |
||
554 | |||
555 | /** |
||
556 | * Set's the attribute option value action instance. |
||
557 | * |
||
558 | * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionValueAction The attribute option value action instance |
||
559 | * |
||
560 | * @return void |
||
561 | */ |
||
562 | public function setAttributeOptionValueAction(ActionInterface $attributeOptionValueAction) |
||
566 | |||
567 | /** |
||
568 | * Return's the attribute option value action instance. |
||
569 | * |
||
570 | * @return \TechDivision\Import\Actions\ActionInterface The attribute option value action instance |
||
571 | */ |
||
572 | public function getAttributeOptionValueAction() |
||
576 | |||
577 | /** |
||
578 | * Set's the attribute option swatch action instance. |
||
579 | * |
||
580 | * @param \TechDivision\Import\Actions\ActionInterface $attributeOptionSwatchAction The attribute option swatch action instance |
||
581 | * |
||
582 | * @return void |
||
583 | */ |
||
584 | public function setAttributeOptionSwatchAction(ActionInterface $attributeOptionSwatchAction) |
||
588 | |||
589 | /** |
||
590 | * Return's the attribute option swatch action instance. |
||
591 | * |
||
592 | * @return \TechDivision\Import\Actions\ActionInterface The attribute option swatch action instance |
||
593 | */ |
||
594 | public function getAttributeOptionSwatchAction() |
||
598 | |||
599 | /** |
||
600 | * Set's the catalog attribute action instance. |
||
601 | * |
||
602 | * @param \TechDivision\Import\Actions\ActionInterface $catalogAttributeAction The catalog attribute action instance |
||
603 | * |
||
604 | * @return void |
||
605 | */ |
||
606 | public function setCatalogAttributeAction(ActionInterface $catalogAttributeAction) |
||
610 | |||
611 | /** |
||
612 | * Return's the catalog attribute action instance. |
||
613 | * |
||
614 | * @return \TechDivision\Import\Actions\ActionInterface The catalog attribute action instance |
||
615 | */ |
||
616 | public function getCatalogAttributeAction() |
||
620 | |||
621 | /** |
||
622 | * Set's the entity attribute action instance. |
||
623 | * |
||
624 | * @param \TechDivision\Import\Actions\ActionInterface $entityAttributeAction The entity attribute action instance |
||
625 | * |
||
626 | * @return void |
||
627 | */ |
||
628 | public function setEntityAttributeAction(ActionInterface $entityAttributeAction) |
||
632 | |||
633 | /** |
||
634 | * Return's the entity attribute action instance. |
||
635 | * |
||
636 | * @return \TechDivision\Import\Actions\ActionInterface The entity attribute action instance |
||
637 | */ |
||
638 | public function getEntityAttributeAction() |
||
642 | |||
643 | /** |
||
644 | * Load's and return's a raw entity without primary key but the mandatory members only and nulled values. |
||
645 | * |
||
646 | * @param string $entityTypeCode The entity type code to return the raw entity for |
||
647 | * @param array $data An array with data that will be used to initialize the raw entity with |
||
648 | * |
||
649 | * @return array The initialized entity |
||
650 | */ |
||
651 | public function loadRawEntity($entityTypeCode, array $data = array()) |
||
655 | |||
656 | /** |
||
657 | * Return's the EAV attribute label with the passed attribute code and store ID. |
||
658 | * |
||
659 | * @param integer $entityTypeId The ID of the EAV entity attribute to return the label for |
||
660 | * @param string $attributeCode The attribute code of the EAV attribute label to return |
||
661 | * @param integer $storeId The store ID of the EAV attribute label to return |
||
662 | * |
||
663 | * @return array The EAV attribute label |
||
664 | */ |
||
665 | public function loadAttributeLabelByEntityTypeIdAndAttributeCodeAndStoreId($entityTypeId, $attributeCode, $storeId) |
||
669 | |||
670 | /** |
||
671 | * Load's and return's the EAV attribute option value with the passed option ID and store ID. |
||
672 | * |
||
673 | * @param string $optionId The option ID |
||
674 | * @param integer $storeId The store ID of the attribute option to load |
||
675 | * |
||
676 | * @return array The EAV attribute option value |
||
677 | */ |
||
678 | public function loadAttributeOptionValueByOptionIdAndStoreId($optionId, $storeId) |
||
682 | |||
683 | /** |
||
684 | * Load's and return's the EAV attribute option swatch with the passed option ID and store ID |
||
685 | * |
||
686 | * @param integer $optionId The option ID of the attribute option swatch to load |
||
687 | * @param integer $storeId The store ID of the attribute option swatch to load |
||
688 | * |
||
689 | * @return array The EAV attribute option swatch |
||
690 | */ |
||
691 | public function loadAttributeOptionSwatchByOptionIdAndStoreId($optionId, $storeId) |
||
695 | |||
696 | /** |
||
697 | * Load's and retur's the EAV catalog attribute with the passed ID. |
||
698 | * |
||
699 | * @param string $attributeId The ID of the EAV catalog attribute to return |
||
700 | * |
||
701 | * @return array The EAV catalog attribute |
||
702 | */ |
||
703 | public function loadCatalogAttribute($attributeId) |
||
707 | |||
708 | /** |
||
709 | * Return's the EAV entity attribute with the passed attribute and attribute set ID. |
||
710 | * |
||
711 | * @param integer $attributeId The ID of the EAV entity attribute's attribute to return |
||
712 | * @param integer $attributeSetId The ID of the EAV entity attribute's attribute set to return |
||
713 | * |
||
714 | * @return array The EAV entity attribute |
||
715 | */ |
||
716 | public function loadEntityAttributeByAttributeIdAndAttributeSetId($attributeId, $attributeSetId) |
||
720 | |||
721 | /** |
||
722 | * Return's the EAV entity attribute with the passed entity type, attribute, attribute set and attribute group ID. |
||
723 | * |
||
724 | * @param integer $entityTypeId The ID of the EAV entity attribute's entity type to return |
||
725 | * @param integer $attributeId The ID of the EAV entity attribute's attribute to return |
||
726 | * @param integer $attributeSetId The ID of the EAV entity attribute's attribute set to return |
||
727 | * @param integer $attributeGroupId The ID of the EAV entity attribute's attribute group to return |
||
728 | * |
||
729 | * @return array The EAV entity attribute |
||
730 | */ |
||
731 | public function loadEntityAttributeByEntityTypeIdAndAttributeIdAndAttributeSetIdAndAttributeGroupId($entityTypeId, $attributeId, $attributeSetId, $attributeGroupId) |
||
735 | |||
736 | /** |
||
737 | * Return's an EAV entity type with the passed entity type code. |
||
738 | * |
||
739 | * @param string $entityTypeCode The code of the entity type to return |
||
740 | * |
||
741 | * @return array The entity type with the passed entity type code |
||
742 | */ |
||
743 | public function loadEntityTypeByEntityTypeCode($entityTypeCode) |
||
747 | |||
748 | /** |
||
749 | * Return's the EAV attribute with the passed entity type ID and code. |
||
750 | * |
||
751 | * @param integer $entityTypeId The entity type ID of the EAV attribute to return |
||
752 | * @param string $attributeCode The code of the EAV attribute to return |
||
753 | * |
||
754 | * @return array The EAV attribute |
||
755 | */ |
||
756 | public function loadAttributeByEntityTypeIdAndAttributeCode($entityTypeId, $attributeCode) |
||
760 | |||
761 | /** |
||
762 | * Load's and return's the EAV attribute option with the passed entity type ID, code, store ID and value. |
||
763 | * |
||
764 | * @param string $entityTypeId The entity type ID of the EAV attribute to load the option for |
||
765 | * @param string $attributeCode The code of the EAV attribute option to load |
||
766 | * @param integer $storeId The store ID of the attribute option to load |
||
767 | * @param string $value The value of the attribute option to load |
||
768 | * |
||
769 | * @return array The EAV attribute option |
||
770 | */ |
||
771 | public function loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value) |
||
775 | |||
776 | /** |
||
777 | * Load's and return's the EAV attribute option with the passed entity type ID and code, store ID, swatch and type. |
||
778 | * |
||
779 | * @param string $entityTypeId The entity type ID of the EAV attribute to load the option for |
||
780 | * @param string $attributeCode The code of the EAV attribute option to load |
||
781 | * @param integer $storeId The store ID of the attribute option to load |
||
782 | * @param string $swatch The swatch of the attribute option to load |
||
783 | * @param string $type The swatch type of the attribute option to load |
||
784 | * |
||
785 | * @return array The EAV attribute option |
||
786 | */ |
||
787 | public function loadAttributeOptionByEntityTypeIdAndAttributeCodeAndStoreIdAndSwatchAndType($entityTypeId, $attributeCode, $storeId, $swatch, $type) |
||
791 | |||
792 | /** |
||
793 | * Load's and return's the EAV attribute option value with the passed code, store ID and value. |
||
794 | * |
||
795 | * @param string $entityTypeId The entity type ID of the EAV attribute to load th option for |
||
796 | * @param string $attributeCode The code of the EAV attribute option to load |
||
797 | * @param integer $storeId The store ID of the attribute option to load |
||
798 | * @param string $value The value of the attribute option to load |
||
799 | * |
||
800 | * @return array The EAV attribute option value |
||
801 | */ |
||
802 | public function loadAttributeOptionValueByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value) |
||
806 | |||
807 | /** |
||
808 | * Load's and return's the EAV attribute option swatch with the passed code, store ID, value and type. |
||
809 | * |
||
810 | * @param string $entityTypeId The entity type ID of the EAV attribute to load th option for |
||
811 | * @param string $attributeCode The code of the EAV attribute option swatch to load |
||
812 | * @param integer $storeId The store ID of the attribute option swatch to load |
||
813 | * @param string $value The value of the attribute option swatch to load |
||
814 | * @param string $type The type of the attribute option swatch to load |
||
815 | * |
||
816 | * @return array The EAV attribute option swatch |
||
817 | */ |
||
818 | public function loadAttributeOptionSwatchByEntityTypeIdAndAttributeCodeAndStoreIdAndValueAndType($entityTypeId, $attributeCode, $storeId, $value, $type) |
||
822 | |||
823 | /** |
||
824 | * Returns the EAV attribute option of attribute with the passed ID with the highest sort order. |
||
825 | * |
||
826 | * @param integer $attributeId The ID of the attribute to return the EAV option with the highest sort order for |
||
827 | * |
||
828 | * @return array|null The EAV attribute option with the highest sort order |
||
829 | */ |
||
830 | public function loadAttributeOptionByAttributeIdAndHighestSortOrder($attributeId) |
||
834 | |||
835 | /** |
||
836 | * Persist's the passed EAV attribute data and return's the ID. |
||
837 | * |
||
838 | * @param array $attribute The attribute data to persist |
||
839 | * @param string|null $name The name of the prepared statement that has to be executed |
||
840 | * |
||
841 | * @return string The ID of the persisted attribute |
||
842 | */ |
||
843 | public function persistAttribute(array $attribute, $name = null) |
||
847 | |||
848 | /** |
||
849 | * Persist the passed attribute label. |
||
850 | * |
||
851 | * @param array $attributeLabel The attribute label to persist |
||
852 | * @param string|null $name The name of the prepared statement that has to be executed |
||
853 | * |
||
854 | * @return void |
||
855 | */ |
||
856 | public function persistAttributeLabel(array $attributeLabel, $name = null) |
||
860 | |||
861 | /** |
||
862 | * Persist's the passed EAV attribute option data and return's the ID. |
||
863 | * |
||
864 | * @param array $attributeOption The attribute option data to persist |
||
865 | * @param string|null $name The name of the prepared statement that has to be executed |
||
866 | * |
||
867 | * @return string The ID of the persisted attribute |
||
868 | */ |
||
869 | public function persistAttributeOption(array $attributeOption, $name = null) |
||
873 | |||
874 | /** |
||
875 | * Persist's the passed EAV attribute option value data and return's the ID. |
||
876 | * |
||
877 | * @param array $attributeOptionValue The attribute option value data to persist |
||
878 | * @param string|null $name The name of the prepared statement that has to be executed |
||
879 | * |
||
880 | * @return void |
||
881 | */ |
||
882 | public function persistAttributeOptionValue(array $attributeOptionValue, $name = null) |
||
886 | |||
887 | /** |
||
888 | * Persist the passed attribute option swatch. |
||
889 | * |
||
890 | * @param array $attributeOptionSwatch The attribute option swatch to persist |
||
891 | * @param string|null $name The name of the prepared statement that has to be executed |
||
892 | * |
||
893 | * @return void |
||
894 | */ |
||
895 | public function persistAttributeOptionSwatch(array $attributeOptionSwatch, $name = null) |
||
899 | |||
900 | /** |
||
901 | * Persist's the passed EAV catalog attribute data and return's the ID. |
||
902 | * |
||
903 | * @param array $catalogAttribute The catalog attribute data to persist |
||
904 | * @param string|null $name The name of the prepared statement that has to be executed |
||
905 | * |
||
906 | * @return void |
||
907 | */ |
||
908 | public function persistCatalogAttribute(array $catalogAttribute, $name = null) |
||
912 | |||
913 | /** |
||
914 | * Persist's the passed EAV entity attribute data and return's the ID. |
||
915 | * |
||
916 | * @param array $entityAttribute The entity attribute data to persist |
||
917 | * @param string|null $name The name of the prepared statement that has to be executed |
||
918 | * |
||
919 | * @return void |
||
920 | */ |
||
921 | public function persistEntityAttribute(array $entityAttribute, $name = null) |
||
925 | |||
926 | /** |
||
927 | * Delete's the EAV attribute with the passed attributes. |
||
928 | * |
||
929 | * @param array $row The attributes of the EAV attribute to delete |
||
930 | * @param string|null $name The name of the prepared statement that has to be executed |
||
931 | * |
||
932 | * @return void |
||
933 | */ |
||
934 | public function deleteAttribute($row, $name = null) |
||
938 | } |
||
939 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.