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 |
||
16 | class MailOptions extends AbstractOptions |
||
17 | { |
||
18 | /** |
||
19 | * Standard adapters aliasses |
||
20 | * @var array |
||
21 | */ |
||
22 | private $adapterMap = [ |
||
23 | 'sendmail' => ['\Zend\Mail\Transport\Sendmail'], |
||
24 | 'smtp' => ['\Zend\Mail\Transport\Smtp'], |
||
25 | 'in_memory' => ['\Zend\Mail\Transport\InMemory', '\Zend\Mail\Transport\Null'], |
||
26 | 'file' => ['\Zend\Mail\Transport\File'], |
||
27 | 'null' => ['\Zend\Mail\Transport\InMemory', '\Zend\Mail\Transport\Null'], |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * @var TransportInterface|string |
||
32 | */ |
||
33 | private $mailAdapter = '\Zend\Mail\Transport\Sendmail'; |
||
34 | /** |
||
35 | * @var MessageOptions; |
||
36 | */ |
||
37 | private $messageOptions; |
||
38 | /** |
||
39 | * @var SmtpOptions; |
||
40 | */ |
||
41 | private $smtpOptions; |
||
42 | /** |
||
43 | * @var FileOptions |
||
44 | */ |
||
45 | private $fileOptions; |
||
46 | /** |
||
47 | * @var array |
||
48 | */ |
||
49 | private $mailListeners = []; |
||
50 | /** |
||
51 | * @var string |
||
52 | */ |
||
53 | private $renderer = 'mailviewrenderer'; |
||
54 | |||
55 | /** |
||
56 | * @return TransportInterface|string |
||
57 | */ |
||
58 | 16 | public function getMailAdapter() |
|
62 | |||
63 | /** |
||
64 | * @param string|TransportInterface $mailAdapter |
||
65 | * @return $this |
||
66 | */ |
||
67 | 8 | public function setMailAdapter($mailAdapter) |
|
83 | |||
84 | /** |
||
85 | * Alias for method getMailAdapter |
||
86 | * @return string|TransportInterface |
||
87 | */ |
||
88 | 2 | public function getTransport() |
|
92 | |||
93 | /** |
||
94 | * Alias for method setMailAdapter |
||
95 | * @param string|TransportInterface $transport |
||
96 | * @return $this |
||
97 | */ |
||
98 | 1 | public function setTransport($transport) |
|
102 | |||
103 | /** |
||
104 | * @return MessageOptions |
||
105 | */ |
||
106 | 18 | public function getMessageOptions() |
|
114 | |||
115 | /** |
||
116 | * @param MessageOptions|array $messageOptions |
||
117 | * @return $this |
||
118 | * @throws \AcMailer\Exception\InvalidArgumentException |
||
119 | */ |
||
120 | 20 | View Code Duplication | public function setMessageOptions($messageOptions) |
135 | |||
136 | /** |
||
137 | * @return SmtpOptions |
||
138 | */ |
||
139 | 3 | public function getSmtpOptions() |
|
147 | |||
148 | /** |
||
149 | * @param SmtpOptions|array $smtpOptions |
||
150 | * @return $this |
||
151 | */ |
||
152 | 4 | View Code Duplication | public function setSmtpOptions($smtpOptions) |
167 | |||
168 | /** |
||
169 | * @return FileOptions |
||
170 | */ |
||
171 | 3 | public function getFileOptions() |
|
179 | |||
180 | /** |
||
181 | * @param FileOptions|array $fileOptions |
||
182 | * @return $this |
||
183 | */ |
||
184 | 4 | View Code Duplication | public function setFileOptions($fileOptions) |
199 | |||
200 | /** |
||
201 | * @return array |
||
202 | */ |
||
203 | 13 | public function getMailListeners() |
|
207 | |||
208 | /** |
||
209 | * @param array $mailListeners |
||
210 | * @return $this |
||
211 | */ |
||
212 | 3 | public function setMailListeners($mailListeners) |
|
217 | |||
218 | /** |
||
219 | * @return string |
||
220 | */ |
||
221 | 12 | public function getRenderer() |
|
225 | |||
226 | /** |
||
227 | * @param string $renderer |
||
228 | * @return $this |
||
229 | */ |
||
230 | 1 | public function setRenderer($renderer) |
|
235 | } |
||
236 |
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.