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 |
||
32 | class CreateMeetingCommand extends Command |
||
33 | { |
||
34 | protected $title; |
||
35 | protected $location; |
||
36 | protected $date; |
||
37 | protected $details; |
||
38 | protected $notifyMembers; |
||
39 | protected $attachments = []; |
||
40 | protected $creatorId; |
||
41 | |||
42 | View Code Duplication | public function __construct($title, $location, $date, $details, $creatorId, array $attachments = [], $notifyMembers = true) |
|
52 | |||
53 | public function getTitle() |
||
57 | |||
58 | public function getLocation() |
||
62 | |||
63 | public function getDate() |
||
67 | |||
68 | public function getDetails() |
||
72 | |||
73 | public function getNotifyMembers() |
||
77 | |||
78 | public function getCreatorId() |
||
82 | |||
83 | public function getAttachments() |
||
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.