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 |
||
| 13 | class Supplier implements SubscriberInterface |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var Connection |
||
| 17 | */ |
||
| 18 | private $connection; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @param Connection $connection |
||
| 22 | */ |
||
| 23 | public function __construct(Connection $connection) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | public static function getSubscribedEvents() |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param \Enlight_Event_EventArgs $args |
||
| 40 | */ |
||
| 41 | View Code Duplication | public function extentBackendSupplier(\Enlight_Event_EventArgs $args) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * @param array $suppliers |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | protected function markConnectSuppliers($suppliers) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param array $supplierIds |
||
| 84 | * @return array |
||
| 85 | */ |
||
| 86 | View Code Duplication | protected function getConnectSuppliers($supplierIds) |
|
| 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.