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 |
||
13 | class Email{ |
||
|
|||
14 | |||
15 | /** |
||
16 | * This is the constructor for Email object. |
||
17 | * |
||
18 | * @access private |
||
19 | */ |
||
20 | private function __construct(){} |
||
21 | |||
22 | /** |
||
23 | * send an email |
||
24 | * |
||
25 | * @access public |
||
26 | * @static static method |
||
27 | * @param string $type Email constant - check config.php |
||
28 | * @param string $email |
||
29 | * @param array $userData |
||
30 | * @param array $data any associated data with the email |
||
31 | * @throws Exception If failed to send the email |
||
32 | */ |
||
33 | public static function sendEmail($type, $email, $userData, $data){ |
||
84 | |||
85 | /** |
||
86 | * Construct the body of Password Reset email |
||
87 | * |
||
88 | * @access private |
||
89 | * @static static method |
||
90 | * @param array $userData |
||
91 | * @param array $data |
||
92 | * @return string The body of the email. |
||
93 | */ |
||
94 | View Code Duplication | private static function getPasswordResetBody($userData, $data){ |
|
104 | |||
105 | /** |
||
106 | * Construct the body of Email Verification email |
||
107 | * |
||
108 | * @access private |
||
109 | * @static static method |
||
110 | * @param array $userData |
||
111 | * @param array $data |
||
112 | * @return string The body of the email. |
||
113 | * |
||
114 | */ |
||
115 | View Code Duplication | private static function getEmailVerificationBody($userData, $data){ |
|
125 | |||
126 | /** |
||
127 | * Construct the body of Revoke Email Changes email |
||
128 | * |
||
129 | * @access private |
||
130 | * @static static method |
||
131 | * @param array $userData |
||
132 | * @param array $data |
||
133 | * @return string The body of the email. |
||
134 | * |
||
135 | */ |
||
136 | View Code Duplication | private static function getRevokeEmailBody($userData, $data){ |
|
146 | |||
147 | /** |
||
148 | * Construct the body of Update Email email |
||
149 | * |
||
150 | * @access private |
||
151 | * @static static method |
||
152 | * @param array $userData |
||
153 | * @param array $data |
||
154 | * @return string The body of the email. |
||
155 | * |
||
156 | */ |
||
157 | View Code Duplication | private static function getUpdateEmailBody($userData, $data){ |
|
167 | |||
168 | /** |
||
169 | * Construct the body of Report Bug, Feature or Enhancement email |
||
170 | * |
||
171 | * @access private |
||
172 | * @static static method |
||
173 | * @param array $userData |
||
174 | * @param array $data |
||
175 | * @return string The body of the email. |
||
176 | * |
||
177 | */ |
||
178 | private static function getReportBugBody($userData, $data){ |
||
187 | |||
188 | } |
||
189 | |||
190 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.