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); |
||
| 51 | class GSDownstreamService { |
||
| 52 | |||
| 53 | |||
| 54 | /** @var string */ |
||
| 55 | private $userId = ''; |
||
| 56 | |||
| 57 | /** @var IURLGenerator */ |
||
| 58 | private $urlGenerator; |
||
| 59 | |||
| 60 | /** @var GSEventsRequest */ |
||
| 61 | private $gsEventsRequest; |
||
| 62 | |||
| 63 | /** @var CirclesRequest */ |
||
| 64 | private $circlesRequest; |
||
| 65 | |||
| 66 | /** @var GlobalScaleService */ |
||
| 67 | private $globalScaleService; |
||
| 68 | |||
| 69 | /** @var ConfigService */ |
||
| 70 | private $configService; |
||
| 71 | |||
| 72 | /** @var MiscService */ |
||
| 73 | private $miscService; |
||
| 74 | |||
| 75 | |||
| 76 | /** |
||
| 77 | * GSUpstreamService constructor. |
||
| 78 | * |
||
| 79 | * @param $userId |
||
| 80 | * @param IURLGenerator $urlGenerator |
||
| 81 | * @param GSEventsRequest $gsEventsRequest |
||
| 82 | * @param CirclesRequest $circlesRequest |
||
| 83 | * @param GlobalScaleService $globalScaleService |
||
| 84 | * @param ConfigService $configService |
||
| 85 | * @param MiscService $miscService |
||
| 86 | */ |
||
| 87 | public function __construct( |
||
| 104 | |||
| 105 | |||
| 106 | /** |
||
| 107 | * @param GSEvent $event |
||
| 108 | * |
||
| 109 | * @throws GSKeyException |
||
| 110 | * @throws GSStatusException |
||
| 111 | * @throws GlobalScaleEventException |
||
| 112 | * @throws CircleDoesNotExistException |
||
| 113 | * @throws ConfigNoCircleAvailableException |
||
| 114 | * @throws GlobalScaleDSyncException |
||
| 115 | */ |
||
| 116 | public function requestedEvent(GSEvent $event) { |
||
| 130 | |||
| 131 | |||
| 132 | /** |
||
| 133 | * @param GSEvent $event |
||
| 134 | * |
||
| 135 | * @throws CircleDoesNotExistException |
||
| 136 | * @throws ConfigNoCircleAvailableException |
||
| 137 | * @throws GSKeyException |
||
| 138 | * @throws GlobalScaleDSyncException |
||
| 139 | * @throws GlobalScaleEventException |
||
| 140 | */ |
||
| 141 | View Code Duplication | public function statusEvent(GSEvent $event) { |
|
| 148 | |||
| 149 | |||
| 150 | /** |
||
| 151 | * @param GSEvent $event |
||
| 152 | */ |
||
| 153 | View Code Duplication | public function onNewEvent(GSEvent $event) { |
|
| 162 | |||
| 163 | } |
||
| 164 | |||
| 165 |
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.