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 |
||
23 | class Crosssell extends \Magento\Checkout\Block\Cart\Crosssell |
||
24 | { |
||
25 | /** |
||
26 | * @var Config |
||
27 | */ |
||
28 | private $_config; |
||
29 | |||
30 | /** |
||
31 | * @var CrosssellModel |
||
32 | */ |
||
33 | private $_crosssell; |
||
34 | |||
35 | /** |
||
36 | * @var Manager |
||
37 | */ |
||
38 | private $_moduleManager; |
||
39 | |||
40 | /** |
||
41 | * Crosssell constructor. |
||
42 | * @param Context $context |
||
43 | * @param Config $config |
||
44 | * @param CrosssellModel $crosssell |
||
45 | * @param ProductFactory $productFactory |
||
46 | * @param Manager $moduleManager |
||
47 | * @param Visibility $productVisibility |
||
48 | * @param Session $checkoutSession |
||
49 | * @param LinkFactory $productLinkFactory |
||
50 | * @param RelatedProducts $itemRelationsList |
||
51 | * @param StockHelper $stockHelper |
||
52 | * @param array $data |
||
53 | */ |
||
54 | View Code Duplication | public function __construct( |
|
81 | |||
82 | /** |
||
83 | * Get the crossell items for the basket page |
||
84 | * |
||
85 | * @return array |
||
86 | */ |
||
87 | public function getItems() |
||
110 | } |
||
111 |
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.