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 |
||
29 | class EmailProvider extends Singleton |
||
30 | { |
||
31 | /** An array of methods that can be used to send email */ |
||
32 | protected $methods; |
||
33 | |||
34 | /** |
||
35 | * Enumerate all supported EmailServices and instacetate them |
||
36 | */ |
||
37 | View Code Duplication | protected function __construct() |
|
51 | |||
52 | /** |
||
53 | * Get the email provider by name |
||
54 | * |
||
55 | * @param string $methodName The class name of the email method |
||
56 | * |
||
57 | * @return false|\Email\EmailService The Email service specified or false if it is not found |
||
58 | */ |
||
59 | View Code Duplication | public function getEmailMethod($methodName) |
|
71 | |||
72 | /** |
||
73 | * Send the email |
||
74 | * |
||
75 | * @param Email\Email $email The email message to send |
||
76 | * @param string $methodName The class name of the email method |
||
77 | * |
||
78 | * @return boolean True if the email was sent, false otherwise |
||
79 | */ |
||
80 | public function sendEmail($email, $methodName = false) |
||
102 | } |
||
103 | /* vim: set tabstop=4 shiftwidth=4 expandtab: */ |
||
105 |
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.