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 |
||
25 | final class InstitutionConfigurationId implements JsonSerializable |
||
26 | { |
||
27 | const UUID_NAMESPACE = '09876543-abcd-0987-abcd-098765432109'; |
||
28 | |||
29 | private $institutionConfigurationId; |
||
30 | |||
31 | /** |
||
32 | * @param Institution $institution |
||
33 | * @return InstitutionConfigurationId |
||
34 | */ |
||
35 | public static function from(Institution $institution) |
||
39 | |||
40 | View Code Duplication | public function __construct($institutionConfigurationId) |
|
60 | |||
61 | /** |
||
62 | * @param InstitutionConfigurationId $otherInstitutionConfigurationId |
||
63 | * @return bool |
||
64 | */ |
||
65 | public function equals(InstitutionConfigurationId $otherInstitutionConfigurationId) |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getInstitutionConfigurationId() |
||
77 | |||
78 | public function __toString() |
||
82 | |||
83 | public function jsonSerialize() |
||
87 | } |
||
88 |
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.