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 |
||
27 | class EmailValidation extends HttpApi |
||
28 | { |
||
29 | /** |
||
30 | * Addresses are validated based off defined checks. |
||
31 | * |
||
32 | * This operation is only accessible with the private API key and not subject to the daily usage limits. |
||
33 | * |
||
34 | * @param string $address An email address to validate. Maximum: 512 characters. |
||
35 | * @param bool $mailboxVerification If set to true, a mailbox verification check will be performed |
||
36 | * against the address. The default is False. |
||
37 | * |
||
38 | * @throws InvalidArgumentException Thrown when local validation returns an error |
||
39 | * @throws HttpClientException Thrown when there's an error on Client side |
||
40 | * @throws HttpServerException Thrown when there's an error on Server side |
||
41 | * @throws \Exception Thrown when we don't catch a Client or Server side Exception |
||
42 | * |
||
43 | * @return ValidateResponse|ResponseInterface |
||
44 | */ |
||
45 | 1 | View Code Duplication | public function validate(string $address, bool $mailboxVerification = false) |
58 | |||
59 | /** |
||
60 | * Parses a delimiter-separated list of email addresses into two lists: parsed addresses and unparsable portions. |
||
61 | * |
||
62 | * The parsed addresses are a list of addresses that are syntactically valid |
||
63 | * (and optionally pass DNS and ESP specific grammar checks). |
||
64 | * |
||
65 | * The unparsable list is a list of character sequences that could not be parsed |
||
66 | * (or optionally failed DNS or ESP specific grammar checks). |
||
67 | * |
||
68 | * Delimiter characters are comma (,) and semicolon (;). |
||
69 | * |
||
70 | * This operation is only accessible with the private API key and not subject to the daily usage limits. |
||
71 | * |
||
72 | * @param string $addresses A delimiter separated list of addresses. Maximum: 8000 characters. |
||
73 | * @param bool $syntaxOnly Perform only syntax checks or DNS and ESP specific validation as well. |
||
74 | * The default is True. |
||
75 | * |
||
76 | * @throws InvalidArgumentException Thrown when local validation returns an error |
||
77 | * @throws HttpClientException Thrown when there's an error on Client side |
||
78 | * @throws HttpServerException Thrown when there's an error on Server side |
||
79 | * @throws \Exception Thrown when we don't catch a Client or Server side Exception |
||
80 | * |
||
81 | * @return ParseResponse|ResponseInterface |
||
82 | */ |
||
83 | 1 | public function parse(string $addresses, bool $syntaxOnly = true) |
|
97 | } |
||
98 |
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.