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 |
||
26 | class SendMessages extends SendMessagesAbstract |
||
27 | { |
||
28 | protected $template = 'update_comment'; |
||
29 | |||
30 | /** |
||
31 | * Returns an instance of Issue. |
||
32 | * |
||
33 | * @return bool |
||
34 | 1 | */ |
|
35 | View Code Duplication | protected function getIssue() |
|
49 | |||
50 | /** |
||
51 | * Returns an instance of Project. |
||
52 | * |
||
53 | * @return Project |
||
54 | 1 | */ |
|
55 | protected function getProject() |
||
59 | |||
60 | /** |
||
61 | * Returns the project id. |
||
62 | * |
||
63 | * @return int |
||
64 | 1 | */ |
|
65 | protected function getProjectId() |
||
69 | |||
70 | /** |
||
71 | * Returns message data belongs to adding a comment. |
||
72 | * |
||
73 | * @param Queue $queue |
||
74 | * |
||
75 | * @return array |
||
76 | 1 | */ |
|
77 | protected function getMessageDataForAddComment(Queue $queue) |
||
90 | |||
91 | /** |
||
92 | * Returns message data belongs to updating a comment. |
||
93 | * |
||
94 | * @param Queue $queue |
||
95 | * |
||
96 | * @return array |
||
97 | 1 | */ |
|
98 | View Code Duplication | protected function getMessageDataForUpdateComment(Queue $queue) |
|
112 | |||
113 | /** |
||
114 | * Returns message data belongs to deleting a note. |
||
115 | * |
||
116 | * @param Queue $queue |
||
117 | * |
||
118 | * @return array |
||
119 | 1 | */ |
|
120 | View Code Duplication | protected function getMessageDataForDeleteComment(Queue $queue) |
|
135 | |||
136 | /** |
||
137 | * Return text to be used for the message heading. |
||
138 | * |
||
139 | * @param Queue $queue |
||
140 | * @param Collection|null $changes |
||
141 | * |
||
142 | * @return string |
||
143 | 1 | */ |
|
144 | protected function getMessageHeading(Queue $queue, Collection $changes = null) |
||
151 | |||
152 | /** |
||
153 | * Check that the issue comment is loaded and the comment is belongs to the issue. |
||
154 | * |
||
155 | * @return bool |
||
156 | 1 | */ |
|
157 | protected function validateData() |
||
161 | |||
162 | /** |
||
163 | * Populate assigned relation in the current issue. |
||
164 | * |
||
165 | * @return void |
||
166 | 1 | */ |
|
167 | View Code Duplication | protected function populateData() |
|
177 | |||
178 | /** |
||
179 | * Check if the latest message is about deleting a comment. |
||
180 | * |
||
181 | * @return bool |
||
182 | 1 | */ |
|
183 | public function isStatusMessage() |
||
187 | |||
188 | /** |
||
189 | * Whether or not the user wants to receive the message. |
||
190 | * |
||
191 | * @param Project\User $user |
||
192 | * @param array $data |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | protected function wantToReceiveMessage(Project\User $user, array $data) |
||
214 | } |
||
215 |
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.