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 declare(strict_types=1); |
||
| 47 | class CircleCreate implements IGlobalScaleEvent { |
||
| 48 | |||
| 49 | |||
| 50 | /** @var CirclesRequest */ |
||
| 51 | private $circlesRequest; |
||
| 52 | |||
| 53 | /** @var MembersRequest */ |
||
| 54 | private $membersRequest; |
||
| 55 | |||
| 56 | /** @var EventsService */ |
||
| 57 | private $eventsService; |
||
| 58 | |||
| 59 | /** @var MiscService */ |
||
| 60 | private $miscService; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * CircleCreate constructor. |
||
| 64 | * |
||
| 65 | * @param CirclesRequest $circlesRequest |
||
| 66 | * @param MembersRequest $membersRequest |
||
| 67 | * @param EventsService $eventsService |
||
| 68 | * @param MiscService $miscService |
||
| 69 | */ |
||
| 70 | View Code Duplication | public function __construct( |
|
| 79 | |||
| 80 | |||
| 81 | /** |
||
| 82 | * Circles are created on the original instance, so return false; |
||
| 83 | * |
||
| 84 | * @param GSEvent $event |
||
| 85 | */ |
||
| 86 | public function verify(GSEvent $event): void { |
||
| 88 | |||
| 89 | |||
| 90 | /** |
||
| 91 | * @param GSEvent $event |
||
| 92 | * |
||
| 93 | * @throws CircleAlreadyExistsException |
||
| 94 | * @throws MemberAlreadyExistsException |
||
| 95 | */ |
||
| 96 | public function manage(GSEvent $event): void { |
||
| 112 | |||
| 113 | } |
||
| 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.