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); |
||
9 | final class EventStatus implements SerializableInterface |
||
10 | { |
||
11 | /** |
||
12 | * @var EventStatusType |
||
13 | */ |
||
14 | private $eventStatusType; |
||
15 | |||
16 | /** |
||
17 | * @var EventStatusReason[] |
||
18 | */ |
||
19 | private $eventStatusReasons; |
||
20 | |||
21 | public function __construct(EventStatusType $eventStatusType, array $eventStatusReasons) |
||
27 | |||
28 | public function getEventStatusType(): EventStatusType |
||
32 | |||
33 | public function getEventStatusReasons(): array |
||
37 | |||
38 | public static function deserialize(array $data): EventStatus |
||
53 | |||
54 | View Code Duplication | public function serialize(): array |
|
66 | |||
67 | View Code Duplication | public function toJsonLd(): array |
|
79 | |||
80 | /** |
||
81 | * @param EventStatusReason[] $eventStatusReasons |
||
82 | */ |
||
83 | private function ensureTranslationsAreUnique(array $eventStatusReasons): void |
||
93 | } |
||
94 |
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.