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 |
||
| 27 | class FootnotesFixPlugin extends BasePlugin implements EventSubscriberInterface |
||
| 28 | { |
||
| 29 | /* ******************************************************************************** |
||
| 30 | * Event handlers |
||
| 31 | * ******************************************************************************** |
||
| 32 | */ |
||
| 33 | public static function getSubscribedEvents() |
||
| 40 | |||
| 41 | public function onItemPostParse(ParseEvent $event) |
||
| 50 | |||
| 51 | public function onPostPublish(BaseEvent $event) |
||
| 57 | |||
| 58 | /* ******************************************************************************** |
||
| 59 | * Implementation |
||
| 60 | * ******************************************************************************** |
||
| 61 | */ |
||
| 62 | |||
| 63 | /** |
||
| 64 | * For a content item to be processed, extract generated footnotes. |
||
| 65 | */ |
||
| 66 | protected function processItem() |
||
| 70 | |||
| 71 | View Code Duplication | protected function fixFootnotes() |
|
| 88 | } |
||
| 89 |
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.