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 StatusMapping 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 | * List of all possible OrderStatus types |
||
43 | * |
||
44 | * @var \Magento\Sales\Model\Config\Source\Order\Status |
||
45 | */ |
||
46 | protected $orderStatus; |
||
47 | |||
48 | /** |
||
49 | * List of all possible TransactionStatus types |
||
50 | * |
||
51 | * @var \Payone\Core\Model\Source\TransactionStatus |
||
52 | */ |
||
53 | protected $transactionStatus; |
||
54 | |||
55 | /** |
||
56 | * Rows cache |
||
57 | * |
||
58 | * @var array|null |
||
59 | */ |
||
60 | private $_arrayRowsCache; |
||
61 | |||
62 | /** |
||
63 | * Constructor |
||
64 | * |
||
65 | * @param \Magento\Backend\Block\Template\Context $context |
||
66 | * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory |
||
67 | * @param \Magento\Sales\Model\Config\Source\Order\Status $orderStatus |
||
68 | * @param \Payone\Core\Model\Source\TransactionStatus $transactionStatus |
||
69 | * @param array $data |
||
70 | * @return void |
||
|
|||
71 | */ |
||
72 | public function __construct( |
||
84 | |||
85 | /** |
||
86 | * Initialise form fields |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | View Code Duplication | protected function _construct() |
|
98 | |||
99 | /** |
||
100 | * Render array cell for prototypeJS template |
||
101 | * |
||
102 | * @param string $columnName |
||
103 | * @return string |
||
104 | */ |
||
105 | public function renderCellTemplate($columnName) |
||
127 | |||
128 | /** |
||
129 | * Obtain existing data from form element |
||
130 | * |
||
131 | * Each row will be instance of \Magento\Framework\DataObject |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | public function getArrayRows() |
||
164 | |||
165 | /** |
||
166 | * Get the grid and scripts contents |
||
167 | * |
||
168 | * @param \Magento\Framework\Data\Form\Element\AbstractElement $element |
||
169 | * @return string |
||
170 | */ |
||
171 | protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) |
||
179 | } |
||
180 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.