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 |
||
19 | class MigrationInfo implements Model |
||
20 | { |
||
21 | protected $onDate; |
||
22 | protected $otherSite; |
||
23 | protected $questionId; |
||
24 | |||
25 | public static function fromProperties(\DateTimeInterface $onDate, $otherSite, $questionId) |
||
35 | |||
36 | View Code Duplication | public static function fromJson(array $data) |
|
50 | |||
51 | public function setOnDate(\DateTimeInterface $onDate = null) |
||
57 | |||
58 | public function getOnDate() |
||
62 | |||
63 | public function setQuestionId($questionId) |
||
69 | |||
70 | public function getQuestionId() |
||
74 | |||
75 | public function setOtherSite(Site $site = null) |
||
81 | |||
82 | public function getOtherSite() |
||
86 | } |
||
87 |
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.