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 KlarnaStoreId extends \Payone\Core\Block\Adminhtml\Config\Form\Field\FieldArray\Multiselect |
||
| 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 TransactionStatus types |
||
| 43 | * |
||
| 44 | * @var \Payone\Core\Model\Source\KlarnaCountry |
||
| 45 | */ |
||
| 46 | protected $klarnaCountries; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Constructor |
||
| 50 | * |
||
| 51 | * @param \Magento\Backend\Block\Template\Context $context |
||
| 52 | * @param \Magento\Framework\Data\Form\Element\Factory $elementFactory |
||
| 53 | * @param \Payone\Core\Model\Source\TransactionStatus $klarnaCountries |
||
| 54 | * @param array $data |
||
| 55 | */ |
||
| 56 | public function __construct( |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Initialise form fields |
||
| 69 | * |
||
| 70 | * @return void |
||
| 71 | */ |
||
| 72 | View Code Duplication | protected function _construct() |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Render array cell for prototypeJS template |
||
| 83 | * |
||
| 84 | * @param string $sColumnName |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | View Code Duplication | public function renderCellTemplate($sColumnName) |
|
| 100 | } |
||
| 101 |
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.