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 |
||
20 | class ProductView extends Action { |
||
21 | |||
22 | /** |
||
23 | * @var SessionManager |
||
24 | */ |
||
25 | protected $_sessionManager; |
||
26 | |||
27 | /** |
||
28 | * @var JsonFactory |
||
29 | */ |
||
30 | protected $_resultJsonFactory; |
||
31 | |||
32 | /** |
||
33 | * ProductView constructor. |
||
34 | * @param Context $context |
||
35 | * @param JsonFactory $resultJsonFactory |
||
36 | * @param SessionManager $sessionManager |
||
37 | * @param CustomerSession $customerSession |
||
38 | * @param Client $eventClient |
||
39 | * @param ProductViewModel $productView |
||
40 | */ |
||
41 | View Code Duplication | public function __construct( |
|
56 | |||
57 | /** |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function execute() |
||
79 | } |
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.