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 |
||
32 | class PersonStatusMapping extends \Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray |
||
33 | { |
||
34 | /** |
||
35 | * Element factory |
||
36 | * |
||
37 | * @var \Magento\Framework\Data\Form\Element\Factory |
||
38 | */ |
||
39 | protected $elementFactory; |
||
40 | |||
41 | /** |
||
42 | * Person status source class |
||
43 | * |
||
44 | * @var \Payone\Core\Model\Source\PersonStatus |
||
45 | */ |
||
46 | protected $personStatus; |
||
47 | |||
48 | /** |
||
49 | * Credit score source class |
||
50 | * |
||
51 | * @var \Payone\Core\Model\Source\CreditScore |
||
52 | */ |
||
53 | protected $creditScore; |
||
54 | |||
55 | /** |
||
56 | * Constructor |
||
57 | * |
||
58 | * @param \Magento\Backend\Block\Template\Context $context |
||
59 | * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory |
||
60 | * @param \Payone\Core\Model\Source\PersonStatus $personStatus |
||
61 | * @param \Payone\Core\Model\Source\CreditScore $creditScore |
||
62 | * @param array $data |
||
63 | */ |
||
64 | public function __construct( |
||
76 | |||
77 | /** |
||
78 | * Initialise form fields |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | protected function _construct() |
||
90 | |||
91 | /** |
||
92 | * Render array cell for prototypeJS template |
||
93 | * |
||
94 | * @param string $columnName |
||
95 | * @return string |
||
96 | */ |
||
97 | View Code Duplication | public function renderCellTemplate($columnName) |
|
114 | } |
||
115 |
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.