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 |
||
18 | class Mail extends GmailConnection |
||
19 | { |
||
20 | use HasDecodableBody, |
||
21 | HasHeaders, |
||
22 | Modifiable, |
||
23 | Replyable { |
||
24 | Replyable::__construct as private __rConstruct; |
||
25 | Modifiable::__construct as private __mConstruct; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * @var |
||
30 | */ |
||
31 | public $id; |
||
32 | |||
33 | /** |
||
34 | * @var |
||
35 | */ |
||
36 | public $internalDate; |
||
37 | |||
38 | /** |
||
39 | * @var |
||
40 | */ |
||
41 | public $labels; |
||
42 | |||
43 | /** |
||
44 | * @var |
||
45 | */ |
||
46 | public $size; |
||
47 | |||
48 | /** |
||
49 | * @var |
||
50 | */ |
||
51 | public $threatId; |
||
52 | |||
53 | /** |
||
54 | * @var \Google_Service_Gmail_MessagePart |
||
55 | */ |
||
56 | public $payload; |
||
57 | |||
58 | /** |
||
59 | * @var Google_Service_Gmail |
||
60 | */ |
||
61 | public $service; |
||
62 | |||
63 | /** |
||
64 | * SingleMessage constructor. |
||
65 | * |
||
66 | * @param \Google_Service_Gmail_Message $message |
||
67 | * @param bool $preload |
||
68 | */ |
||
69 | public function __construct( \Google_Service_Gmail_Message $message, $preload = false ) |
||
89 | |||
90 | /** |
||
91 | * Returns ID of the email |
||
92 | * |
||
93 | * @return string |
||
94 | */ |
||
95 | public function getId() |
||
99 | |||
100 | /** |
||
101 | * Return a UNIX version of the date |
||
102 | * |
||
103 | * @return int UNIX date |
||
104 | */ |
||
105 | public function getInternalDate() |
||
109 | |||
110 | /** |
||
111 | * Returns the labels of the email |
||
112 | * Example: INBOX, STARRED, UNREAD |
||
113 | * |
||
114 | * @return mixed |
||
115 | */ |
||
116 | public function getLabels() |
||
120 | |||
121 | /** |
||
122 | * Returns approximate size of the email |
||
123 | * |
||
124 | * @return mixed |
||
125 | */ |
||
126 | public function getSize() |
||
130 | |||
131 | /** |
||
132 | * Returns threat ID of the email |
||
133 | * |
||
134 | * @return string |
||
135 | */ |
||
136 | public function getThreatId() |
||
140 | |||
141 | /** |
||
142 | * Returns all the headers of the email |
||
143 | * |
||
144 | * @return \Google_Service_Gmail_MessagePartHeader |
||
145 | */ |
||
146 | public function getHeaders() |
||
150 | |||
151 | /** |
||
152 | * Returns the subject of the email |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | public function getSubject() |
||
160 | |||
161 | public function getFrom() |
||
171 | |||
172 | /** |
||
173 | * Returns the original date that the email was sent |
||
174 | * |
||
175 | * @return Carbon |
||
176 | */ |
||
177 | public function getDate() |
||
181 | |||
182 | /** |
||
183 | * Returns email of the original recipient |
||
184 | * |
||
185 | * @return string |
||
186 | */ |
||
187 | public function getDeliveredTo() |
||
191 | |||
192 | /** |
||
193 | * @param bool $raw |
||
194 | * |
||
195 | * @return bool|string |
||
196 | */ |
||
197 | View Code Duplication | public function getPlainTextBody( $raw = false ) |
|
205 | |||
206 | /** |
||
207 | * @return string base64 version of the body |
||
208 | */ |
||
209 | public function getRawPlainTextBody() |
||
213 | |||
214 | /** |
||
215 | * @param bool $raw |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | View Code Duplication | public function getHtmlBody( $raw = false ) |
|
227 | |||
228 | /** |
||
229 | * @return string base64 version of the body |
||
230 | */ |
||
231 | public function getRawHtmlBody() |
||
235 | |||
236 | public function getAttachments() |
||
258 | |||
259 | /** |
||
260 | * @return boolean |
||
261 | */ |
||
262 | public function hasAttachments() |
||
278 | |||
279 | /** |
||
280 | * @param string $type |
||
281 | * |
||
282 | * @return \Google_Service_Gmail_MessagePart|null |
||
283 | */ |
||
284 | private function getBodyPart( $type = 'text/html' ) |
||
305 | |||
306 | /** |
||
307 | * Get's the gmail information from the Mail |
||
308 | * |
||
309 | * @return Mail |
||
310 | */ |
||
311 | public function load() |
||
317 | } |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.