Complex classes like ProductBunchProcessor 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 ProductBunchProcessor, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
32 | class ProductBunchProcessor implements ProductBunchProcessorInterface |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * A PDO connection initialized with the values from the Doctrine EntityManager. |
||
37 | * |
||
38 | * @var \PDO |
||
39 | */ |
||
40 | protected $connection; |
||
41 | |||
42 | /** |
||
43 | * The repository to access EAV attribute option values. |
||
44 | * |
||
45 | * @var \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository |
||
46 | */ |
||
47 | protected $eavAttributeOptionValueRepository; |
||
48 | |||
49 | /** |
||
50 | * The action for product CRUD methods. |
||
51 | * |
||
52 | * @var \TechDivision\Import\Product\Actions\ProductAction |
||
53 | */ |
||
54 | protected $productAction; |
||
55 | |||
56 | /** |
||
57 | * The action for product varchar attribute CRUD methods. |
||
58 | * |
||
59 | * @var \TechDivision\Import\Product\Actions\ProductVarcharAction |
||
60 | */ |
||
61 | protected $productVarcharAction; |
||
62 | |||
63 | /** |
||
64 | * The action for product text attribute CRUD methods. |
||
65 | * |
||
66 | * @var \TechDivision\Import\Product\Actions\ProductTextAction |
||
67 | */ |
||
68 | protected $productTextAction; |
||
69 | |||
70 | /** |
||
71 | * The action for product int attribute CRUD methods. |
||
72 | * |
||
73 | * @var \TechDivision\Import\Product\Actions\ProductIntAction |
||
74 | */ |
||
75 | protected $productIntAction; |
||
76 | |||
77 | /** |
||
78 | * The action for product decimal attribute CRUD methods. |
||
79 | * |
||
80 | * @var \TechDivision\Import\Product\Actions\ProductDecimalAction |
||
81 | */ |
||
82 | protected $productDecimalAction; |
||
83 | |||
84 | /** |
||
85 | * The action for product datetime attribute CRUD methods. |
||
86 | * |
||
87 | * @var \TechDivision\Import\Product\Actions\ProductDatetimeAction |
||
88 | */ |
||
89 | protected $productDatetimeAction; |
||
90 | |||
91 | /** |
||
92 | * The action for product website CRUD methods. |
||
93 | * |
||
94 | * @var \TechDivision\Import\Product\Actions\ProductWebsiteAction |
||
95 | */ |
||
96 | protected $productWebsiteAction; |
||
97 | |||
98 | /** |
||
99 | * The action for product category CRUD methods. |
||
100 | * |
||
101 | * @var \TechDivision\Import\Product\Actions\ProductCategoryAction |
||
102 | */ |
||
103 | protected $productCategoryAction; |
||
104 | |||
105 | /** |
||
106 | * The action for stock item CRUD methods. |
||
107 | * |
||
108 | * @var \TechDivision\Import\Product\Actions\StockItemAction |
||
109 | */ |
||
110 | protected $stockItemAction; |
||
111 | |||
112 | /** |
||
113 | * The action for stock status CRUD methods. |
||
114 | * |
||
115 | * @var \TechDivision\Import\Product\Actions\StockStatusAction |
||
116 | */ |
||
117 | protected $stockStatusAction; |
||
118 | |||
119 | /** |
||
120 | * The action for URL rewrite CRUD methods. |
||
121 | * |
||
122 | * @var \TechDivision\Import\Product\Actions\UrlRewriteAction |
||
123 | */ |
||
124 | protected $urlRewriteAction; |
||
125 | |||
126 | /** |
||
127 | * The repository to load the URL rewrites with. |
||
128 | * |
||
129 | * @var \TechDivision\Import\Product\Repositories\UrlRewriteRepository |
||
130 | */ |
||
131 | protected $urlRewriteRepository; |
||
132 | |||
133 | /** |
||
134 | * Set's the passed connection. |
||
135 | * |
||
136 | * @param \PDO $connection The connection to set |
||
137 | * |
||
138 | * @return void |
||
139 | */ |
||
140 | public function setConnection(\PDO $connection) |
||
144 | |||
145 | /** |
||
146 | * Return's the connection. |
||
147 | * |
||
148 | * @return \PDO The connection instance |
||
149 | */ |
||
150 | public function getConnection() |
||
154 | |||
155 | /** |
||
156 | * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
||
157 | * object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
||
158 | * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
||
159 | * to autocommit mode. |
||
160 | * |
||
161 | * @return boolean Returns TRUE on success or FALSE on failure |
||
162 | * @link http://php.net/manual/en/pdo.begintransaction.php |
||
163 | */ |
||
164 | public function beginTransaction() |
||
168 | |||
169 | /** |
||
170 | * Commits a transaction, returning the database connection to autocommit mode until the next call to |
||
171 | * ProductProcessor::beginTransaction() starts a new transaction. |
||
172 | * |
||
173 | * @return boolean Returns TRUE on success or FALSE on failure |
||
174 | * @link http://php.net/manual/en/pdo.commit.php |
||
175 | */ |
||
176 | public function commit() |
||
180 | |||
181 | /** |
||
182 | * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
||
183 | * |
||
184 | * If the database was set to autocommit mode, this function will restore autocommit mode after it has |
||
185 | * rolled back the transaction. |
||
186 | * |
||
187 | * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
||
188 | * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
||
189 | * COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
||
190 | * |
||
191 | * @return boolean Returns TRUE on success or FALSE on failure |
||
192 | * @link http://php.net/manual/en/pdo.rollback.php |
||
193 | */ |
||
194 | public function rollBack() |
||
198 | |||
199 | /** |
||
200 | * Set's the repository to access EAV attribute option values. |
||
201 | * |
||
202 | * @param \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository $eavAttributeOptionValueRepository The repository to access EAV attribute option values |
||
203 | * |
||
204 | * @return void |
||
205 | */ |
||
206 | public function setEavAttributeOptionValueRepository($eavAttributeOptionValueRepository) |
||
210 | |||
211 | /** |
||
212 | * Return's the repository to access EAV attribute option values. |
||
213 | * |
||
214 | * @return \TechDivision\Import\Product\Repositories\EavAttributeOptionValueRepository The repository instance |
||
215 | */ |
||
216 | public function getEavAttributeOptionValueRepository() |
||
220 | |||
221 | /** |
||
222 | * Set's the action with the product CRUD methods. |
||
223 | * |
||
224 | * @param \TechDivision\Import\Product\Actions\ProductAction $productAction The action with the product CRUD methods |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | public function setProductAction($productAction) |
||
232 | |||
233 | /** |
||
234 | * Return's the action with the product CRUD methods. |
||
235 | * |
||
236 | * @return \TechDivision\Import\Product\Actions\ProductAction The action instance |
||
237 | */ |
||
238 | public function getProductAction() |
||
242 | |||
243 | /** |
||
244 | * Set's the action with the product varchar attribute CRUD methods. |
||
245 | * |
||
246 | * @param \TechDivision\Import\Product\Actions\ProductVarcharAction $productVarcharAction The action with the product varchar attriute CRUD methods |
||
247 | * |
||
248 | * @return void |
||
249 | */ |
||
250 | public function setProductVarcharAction($productVarcharAction) |
||
254 | |||
255 | /** |
||
256 | * Return's the action with the product varchar attribute CRUD methods. |
||
257 | * |
||
258 | * @return \TechDivision\Import\Product\Actions\ProductVarcharAction The action instance |
||
259 | */ |
||
260 | public function getProductVarcharAction() |
||
264 | |||
265 | /** |
||
266 | * Set's the action with the product text attribute CRUD methods. |
||
267 | * |
||
268 | * @param \TechDivision\Import\Product\Actions\ProductTextAction $productTextAction The action with the product text attriute CRUD methods |
||
269 | * |
||
270 | * @return void |
||
271 | */ |
||
272 | public function setProductTextAction($productTextAction) |
||
276 | |||
277 | /** |
||
278 | * Return's the action with the product text attribute CRUD methods. |
||
279 | * |
||
280 | * @return \TechDivision\Import\Product\Actions\ProductTextAction The action instance |
||
281 | */ |
||
282 | public function getProductTextAction() |
||
286 | |||
287 | /** |
||
288 | * Set's the action with the product int attribute CRUD methods. |
||
289 | * |
||
290 | * @param \TechDivision\Import\Product\Actions\ProductIntAction $productIntAction The action with the product int attriute CRUD methods |
||
291 | * |
||
292 | * @return void |
||
293 | */ |
||
294 | public function setProductIntAction($productIntAction) |
||
298 | |||
299 | /** |
||
300 | * Return's the action with the product int attribute CRUD methods. |
||
301 | * |
||
302 | * @return \TechDivision\Import\Product\Actions\ProductIntAction The action instance |
||
303 | */ |
||
304 | public function getProductIntAction() |
||
308 | |||
309 | /** |
||
310 | * Set's the action with the product decimal attribute CRUD methods. |
||
311 | * |
||
312 | * @param \TechDivision\Import\Product\Actions\ProductDecimalAction $productDecimalAction The action with the product decimal attriute CRUD methods |
||
313 | * |
||
314 | * @return void |
||
315 | */ |
||
316 | public function setProductDecimalAction($productDecimalAction) |
||
320 | |||
321 | /** |
||
322 | * Return's the action with the product decimal attribute CRUD methods. |
||
323 | * |
||
324 | * @return \TechDivision\Import\Product\Actions\ProductDecimalAction The action instance |
||
325 | */ |
||
326 | public function getProductDecimalAction() |
||
330 | |||
331 | /** |
||
332 | * Set's the action with the product datetime attribute CRUD methods. |
||
333 | * |
||
334 | * @param \TechDivision\Import\Product\Actions\ProductDatetimeAction $productDatetimeAction The action with the product datetime attriute CRUD methods |
||
335 | * |
||
336 | * @return void |
||
337 | */ |
||
338 | public function setProductDatetimeAction($productDatetimeAction) |
||
342 | |||
343 | /** |
||
344 | * Return's the action with the product datetime attribute CRUD methods. |
||
345 | * |
||
346 | * @return \TechDivision\Import\Product\Actions\ProductDatetimeAction The action instance |
||
347 | */ |
||
348 | public function getProductDatetimeAction() |
||
352 | |||
353 | /** |
||
354 | * Set's the action with the product website CRUD methods. |
||
355 | * |
||
356 | * @param \TechDivision\Import\Product\Actions\ProductWebsiteAction $productWebsiteAction The action with the product website CRUD methods |
||
357 | * |
||
358 | * @return void |
||
359 | */ |
||
360 | public function setProductWebsiteAction($productWebsiteAction) |
||
364 | |||
365 | /** |
||
366 | * Return's the action with the product website CRUD methods. |
||
367 | * |
||
368 | * @return \TechDivision\Import\Product\Actions\ProductWebsiteAction The action instance |
||
369 | */ |
||
370 | public function getProductWebsiteAction() |
||
374 | |||
375 | /** |
||
376 | * Set's the action with the product category CRUD methods. |
||
377 | * |
||
378 | * @param \TechDivision\Import\Product\Actions\ProductCategoryAction $productCategoryAction The action with the product category CRUD methods |
||
379 | * |
||
380 | * @return void |
||
381 | */ |
||
382 | public function setProductCategoryAction($productCategoryAction) |
||
386 | |||
387 | /** |
||
388 | * Return's the action with the product category CRUD methods. |
||
389 | * |
||
390 | * @return \TechDivision\Import\Product\Actions\ProductCategoryAction The action instance |
||
391 | */ |
||
392 | public function getProductCategoryAction() |
||
396 | |||
397 | /** |
||
398 | * Set's the action with the stock item CRUD methods. |
||
399 | * |
||
400 | * @param \TechDivision\Import\Product\Actions\StockItemAction $stockItemAction The action with the stock item CRUD methods |
||
401 | * |
||
402 | * @return void |
||
403 | */ |
||
404 | public function setStockItemAction($stockItemAction) |
||
408 | |||
409 | /** |
||
410 | * Return's the action with the stock item CRUD methods. |
||
411 | * |
||
412 | * @return \TechDivision\Import\Product\Actions\StockItemAction The action instance |
||
413 | */ |
||
414 | public function getStockItemAction() |
||
418 | |||
419 | /** |
||
420 | * Set's the action with the stock status CRUD methods. |
||
421 | * |
||
422 | * @param \TechDivision\Import\Product\Actions\StockStatusAction $stockStatusAction The action with the stock status CRUD methods |
||
423 | * |
||
424 | * @return void |
||
425 | */ |
||
426 | public function setStockStatusAction($stockStatusAction) |
||
430 | |||
431 | /** |
||
432 | * Return's the action with the stock status CRUD methods. |
||
433 | * |
||
434 | * @return \TechDivision\Import\Product\Actions\StockStatusAction The action instance |
||
435 | */ |
||
436 | public function getStockStatusAction() |
||
440 | |||
441 | /** |
||
442 | * Set's the action with the URL rewrite CRUD methods. |
||
443 | * |
||
444 | * @param \TechDivision\Import\Product\Actions\UrlRewriteAction $urlRewriteAction The action with the URL rewrite CRUD methods |
||
445 | * |
||
446 | * @return void |
||
447 | */ |
||
448 | public function setUrlRewriteAction($urlRewriteAction) |
||
452 | |||
453 | /** |
||
454 | * Return's the action with the stock status CRUD methods. |
||
455 | * |
||
456 | * @return \TechDivision\Import\Product\Actions\UrlRewriteAction The action instance |
||
457 | */ |
||
458 | public function getUrlRewriteAction() |
||
462 | |||
463 | /** |
||
464 | * Set's the repository to load the URL rewrites with. |
||
465 | * |
||
466 | * @param \TechDivision\Import\Product\Repositories\UrlRewriteRepository $urlRewriteRepository The repository instance |
||
467 | * |
||
468 | * @return void |
||
469 | */ |
||
470 | public function setUrlRewriteRepository($urlRewriteRepository) |
||
474 | |||
475 | /** |
||
476 | * Return's the repository to load the URL rewrites with. |
||
477 | * |
||
478 | * @return \TechDivision\Import\Product\Repositories\UrlRewriteRepository The repository instance |
||
479 | */ |
||
480 | public function getUrlRewriteRepository() |
||
484 | |||
485 | /** |
||
486 | * Return's the attribute option value with the passed value and store ID. |
||
487 | * |
||
488 | * @param mixed $value The option value |
||
489 | * @param integer $storeId The ID of the store |
||
490 | * |
||
491 | * @return array|boolean The attribute option value instance |
||
492 | */ |
||
493 | public function getEavAttributeOptionValueByOptionValueAndStoreId($value, $storeId) |
||
497 | |||
498 | /** |
||
499 | * Return's the URL rewrites for the passed URL entity type and ID. |
||
500 | * |
||
501 | * @param string $entityType The entity type to load the URL rewrites for |
||
502 | * @param integer $entityId The entity ID to laod the rewrites for |
||
503 | * |
||
504 | * @return array The URL rewrites |
||
505 | */ |
||
506 | public function getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId) |
||
510 | |||
511 | /** |
||
512 | * Persist's the passed product data and return's the ID. |
||
513 | * |
||
514 | * @param array $product The product data to persist |
||
515 | * @param string|null $name The name of the prepared statement that has to be executed |
||
516 | * |
||
517 | * @return string The ID of the persisted entity |
||
518 | */ |
||
519 | public function persistProduct($product, $name = null) |
||
523 | |||
524 | /** |
||
525 | * Persist's the passed product varchar attribute. |
||
526 | * |
||
527 | * @param array $attribute The attribute to persist |
||
528 | * @param string|null $name The name of the prepared statement that has to be executed |
||
529 | * |
||
530 | * @return void |
||
531 | */ |
||
532 | public function persistProductVarcharAttribute($attribute, $name = null) |
||
536 | |||
537 | /** |
||
538 | * Persist's the passed product integer attribute. |
||
539 | * |
||
540 | * @param array $attribute The attribute to persist |
||
541 | * @param string|null $name The name of the prepared statement that has to be executed |
||
542 | * |
||
543 | * @return void |
||
544 | */ |
||
545 | public function persistProductIntAttribute($attribute, $name = null) |
||
549 | |||
550 | /** |
||
551 | * Persist's the passed product decimal attribute. |
||
552 | * |
||
553 | * @param array $attribute The attribute to persist |
||
554 | * @param string|null $name The name of the prepared statement that has to be executed |
||
555 | * |
||
556 | * @return void |
||
557 | */ |
||
558 | public function persistProductDecimalAttribute($attribute, $name = null) |
||
562 | |||
563 | /** |
||
564 | * Persist's the passed product datetime attribute. |
||
565 | * |
||
566 | * @param array $attribute The attribute to persist |
||
567 | * @param string|null $name The name of the prepared statement that has to be executed |
||
568 | * |
||
569 | * @return void |
||
570 | */ |
||
571 | public function persistProductDatetimeAttribute($attribute, $name = null) |
||
575 | |||
576 | /** |
||
577 | * Persist's the passed product text attribute. |
||
578 | * |
||
579 | * @param array $attribute The attribute to persist |
||
580 | * @param string|null $name The name of the prepared statement that has to be executed |
||
581 | * |
||
582 | * @return void |
||
583 | */ |
||
584 | public function persistProductTextAttribute($attribute, $name = null) |
||
588 | |||
589 | /** |
||
590 | * Persist's the passed product website data and return's the ID. |
||
591 | * |
||
592 | * @param array $productWebsite The product website data to persist |
||
593 | * @param string|null $name The name of the prepared statement that has to be executed |
||
594 | * |
||
595 | * @return void |
||
596 | */ |
||
597 | public function persistProductWebsite($productWebsite, $name = null) |
||
601 | |||
602 | /** |
||
603 | * Persist's the passed product category data and return's the ID. |
||
604 | * |
||
605 | * @param array $productCategory The product category data to persist |
||
606 | * @param string|null $name The name of the prepared statement that has to be executed |
||
607 | * |
||
608 | * @return void |
||
609 | */ |
||
610 | public function persistProductCategory($productCategory, $name = null) |
||
614 | |||
615 | /** |
||
616 | * Persist's the passed stock item data and return's the ID. |
||
617 | * |
||
618 | * @param array $stockItem The stock item data to persist |
||
619 | * @param string|null $name The name of the prepared statement that has to be executed |
||
620 | * |
||
621 | * @return void |
||
622 | */ |
||
623 | public function persistStockItem($stockItem, $name = null) |
||
627 | |||
628 | /** |
||
629 | * Persist's the passed stock status data and return's the ID. |
||
630 | * |
||
631 | * @param array $stockStatus The stock status data to persist |
||
632 | * @param string|null $name The name of the prepared statement that has to be executed |
||
633 | * |
||
634 | * @return void |
||
635 | */ |
||
636 | public function persistStockStatus($stockStatus, $name = null) |
||
640 | |||
641 | /** |
||
642 | * Persist's the URL write with the passed data. |
||
643 | * |
||
644 | * @param array $row The URL rewrite to persist |
||
645 | * @param string|null $name The name of the prepared statement that has to be executed |
||
646 | * |
||
647 | * @return void |
||
648 | */ |
||
649 | public function persistUrlRewrite($row, $name = null) |
||
653 | |||
654 | /** |
||
655 | * Remove's the entity with the passed attributes. |
||
656 | * |
||
657 | * @param array $row The attributes of the entity to remove |
||
658 | * @param string|null $name The name of the prepared statement that has to be executed |
||
659 | * |
||
660 | * @return void |
||
661 | */ |
||
662 | public function removeProduct($row, $name = null) |
||
666 | |||
667 | /** |
||
668 | * Delete's the URL rewrite with the passed attributes. |
||
669 | * |
||
670 | * @param array $row The attributes of the entity to remove |
||
671 | * @param string|null $name The name of the prepared statement that has to be executed |
||
672 | * |
||
673 | * @return void |
||
674 | */ |
||
675 | public function removeUrlRewrite($row, $name = null) |
||
679 | |||
680 | /** |
||
681 | * Delete's the stock item(s) with the passed attributes. |
||
682 | * |
||
683 | * @param array $row The attributes of the entity to remove |
||
684 | * @param string|null $name The name of the prepared statement that has to be executed |
||
685 | * |
||
686 | * @return void |
||
687 | */ |
||
688 | public function removeStockItem($row, $name = null) |
||
692 | |||
693 | /** |
||
694 | * Delete's the stock status with the passed attributes. |
||
695 | * |
||
696 | * @param array $row The attributes of the entity to remove |
||
697 | * @param string|null $name The name of the prepared statement that has to be executed |
||
698 | * |
||
699 | * @return void |
||
700 | */ |
||
701 | public function removeStockStatus($row, $name = null) |
||
705 | |||
706 | /** |
||
707 | * Delete's the product website relations with the passed attributes. |
||
708 | * |
||
709 | * @param array $row The attributes of the entity to remove |
||
710 | * @param string|null $name The name of the prepared statement that has to be executed |
||
711 | * |
||
712 | * @return void |
||
713 | */ |
||
714 | public function removeProductWebsite($row, $name = null) |
||
718 | |||
719 | /** |
||
720 | * Delete's the product category relations with the passed attributes. |
||
721 | * |
||
722 | * @param array $row The attributes of the entity to remove |
||
723 | * @param string|null $name The name of the prepared statement that has to be executed |
||
724 | * |
||
725 | * @return void |
||
726 | */ |
||
727 | public function removeProductCategory($row, $name = null) |
||
731 | } |
||
732 |