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 Domain extends BaseObject |
||
27 | { |
||
28 | const CACHE_FORWARDERS = 'forwarders'; |
||
29 | const CACHE_MAILBOXES = 'mailboxes'; |
||
30 | const CACHE_SUBDOMAINS = 'subdomains'; |
||
31 | |||
32 | const CATCHALL_BLACKHOLE = ':blackhole:'; |
||
33 | const CATCHALL_FAIL = ':fail:'; |
||
34 | |||
35 | /** @var string */ |
||
36 | private $domainName; |
||
37 | |||
38 | /** @var User */ |
||
39 | private $owner; |
||
40 | |||
41 | /** @var string[] */ |
||
42 | private $aliases; |
||
43 | |||
44 | /** @var string[] */ |
||
45 | private $pointers; |
||
46 | |||
47 | /** @var float */ |
||
48 | private $bandwidthUsed; |
||
49 | |||
50 | /** @var float|null */ |
||
51 | private $bandwidthLimit; |
||
52 | |||
53 | /** @var float */ |
||
54 | private $diskUsage; |
||
55 | |||
56 | /** |
||
57 | * Construct the object. |
||
58 | * |
||
59 | * @param string $name The domain name |
||
60 | * @param UserContext $context The owning user context |
||
61 | * @param string|array $config The basic config string as returned by CMD_API_ADDITIONAL_DOMAINS |
||
62 | */ |
||
63 | public function __construct($name, UserContext $context, $config) |
||
87 | |||
88 | /** |
||
89 | * Creates a new domain under the specified user. |
||
90 | * |
||
91 | * @param User $user Owner of the domain |
||
92 | * @param string $domainName Domain name to create |
||
93 | * @param float|null $bandwidthLimit Bandwidth limit in MB, or NULL to share with account |
||
94 | * @param float|null $diskLimit Disk limit in MB, or NULL to share with account |
||
95 | * @param bool|null $ssl Whether SSL is to be enabled, or NULL to fallback to account default |
||
96 | * @param bool|null $php Whether PHP is to be enabled, or NULL to fallback to account default |
||
97 | * @param bool|null $cgi Whether CGI is to be enabled, or NULL to fallback to account default |
||
98 | * @return Domain The newly created domain |
||
99 | */ |
||
100 | public static function create(User $user, $domainName, $bandwidthLimit = null, $diskLimit = null, $ssl = null, $php = null, $cgi = null) |
||
115 | |||
116 | /** |
||
117 | * Creates a new email forwarder. |
||
118 | * |
||
119 | * @param string $prefix Part of the email address before the @ |
||
120 | * @param string|string[] $recipients One or more recipients |
||
121 | * @return Forwarder The newly created forwarder |
||
122 | */ |
||
123 | public function createForwarder($prefix, $recipients) |
||
127 | |||
128 | /** |
||
129 | * Creates a new mailbox. |
||
130 | * |
||
131 | * @param string $prefix Prefix for the account |
||
132 | * @param string $password Password for the account |
||
133 | * @param int|null $quota Quota in megabytes, or zero/null for unlimited |
||
134 | * @param int|null $sendLimit Send limit, or 0 for unlimited, or null for system default |
||
135 | * @return Mailbox The newly created mailbox |
||
136 | */ |
||
137 | public function createMailbox($prefix, $password, $quota = null, $sendLimit = null) |
||
141 | |||
142 | /** |
||
143 | * Creates a pointer or alias. |
||
144 | * |
||
145 | * @param string $domain |
||
146 | * @param bool $alias |
||
147 | */ |
||
148 | public function createPointer($domain, $alias = false) |
||
165 | |||
166 | /** |
||
167 | * Creates a new subdomain. |
||
168 | * |
||
169 | * @param string $prefix Prefix to add before the domain name |
||
170 | * @return Subdomain The newly created subdomain |
||
171 | */ |
||
172 | public function createSubdomain($prefix) |
||
176 | |||
177 | /** |
||
178 | * Deletes this domain from the user. |
||
179 | */ |
||
180 | public function delete() |
||
189 | |||
190 | /** |
||
191 | * @return string[] List of aliases for this domain |
||
192 | */ |
||
193 | public function getAliases() |
||
197 | |||
198 | /** |
||
199 | * @return float Bandwidth used in megabytes |
||
200 | */ |
||
201 | public function getBandwidthUsed() |
||
205 | |||
206 | /** |
||
207 | * @return float|null Bandwidth quotum in megabytes, or NULL for unlimited |
||
208 | */ |
||
209 | public function getBandwidthLimit() |
||
213 | |||
214 | /** |
||
215 | * @return string|null Currently configured catch-all configuration |
||
216 | */ |
||
217 | public function getCatchall() |
||
222 | |||
223 | /** |
||
224 | * @return float Disk usage in megabytes |
||
225 | */ |
||
226 | public function getDiskUsage() |
||
230 | |||
231 | /** |
||
232 | * @return string The real domain name |
||
233 | */ |
||
234 | public function getDomainName() |
||
238 | |||
239 | /** |
||
240 | * Returns unified sorted list of main domain name, aliases and pointers. |
||
241 | * |
||
242 | * @return string[] |
||
243 | */ |
||
244 | public function getDomainNames() |
||
252 | |||
253 | /** |
||
254 | * @return Forwarder[] Associative array of forwarders |
||
255 | */ |
||
256 | View Code Duplication | public function getForwarders() |
|
265 | |||
266 | /** |
||
267 | * @return Mailbox[] Associative array of mailboxes |
||
268 | */ |
||
269 | View Code Duplication | public function getMailboxes() |
|
279 | |||
280 | /** |
||
281 | * @return User |
||
282 | */ |
||
283 | public function getOwner() |
||
287 | |||
288 | /** |
||
289 | * @return string[] List of domain pointers for this domain |
||
290 | */ |
||
291 | public function getPointers() |
||
295 | |||
296 | /** |
||
297 | * @return Subdomain[] Associative array of subdomains |
||
298 | */ |
||
299 | public function getSubdomains() |
||
307 | |||
308 | /** |
||
309 | * Invokes a POST command on a domain object. |
||
310 | * |
||
311 | * @param string $command Command to invoke |
||
312 | * @param string $action Action to execute |
||
313 | * @param array $parameters Additional options for the command |
||
314 | * @param bool $clearCache Whether to clear the domain cache on success |
||
315 | * @return array Response from the API |
||
316 | */ |
||
317 | public function invokePost($command, $action, $parameters = [], $clearCache = true) |
||
328 | |||
329 | /** |
||
330 | * @param string $newValue New address for the catch-all, or one of the CATCHALL_ constants |
||
331 | */ |
||
332 | public function setCatchall($newValue) |
||
338 | |||
339 | /** |
||
340 | * Allows Domain object to be passed as a string with its domain name. |
||
341 | * |
||
342 | * @return string |
||
343 | */ |
||
344 | public function __toString() |
||
348 | } |
||
349 |