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 |
||
9 | class EmailCount extends HunterClient |
||
10 | { |
||
11 | /** |
||
12 | * Domain name from which you want to find the email addresses |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | public $domain; |
||
17 | |||
18 | /** |
||
19 | * The company name from which you want to find the email addresses |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | public $company; |
||
24 | |||
25 | /** |
||
26 | * Specifies the type of email addresses to return |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | public $type; |
||
31 | |||
32 | public function __construct() |
||
36 | |||
37 | /** |
||
38 | * Sets domain to search |
||
39 | * |
||
40 | * @param string $domain |
||
41 | * @return DomainSearch |
||
42 | */ |
||
43 | public function domain(string $domain): self |
||
49 | |||
50 | /** |
||
51 | * Set company name to search |
||
52 | * |
||
53 | * @param string $company |
||
54 | * @return DomainSearch |
||
55 | */ |
||
56 | public function company(string $company): self |
||
62 | |||
63 | /** |
||
64 | * Set the type of email addresses to include in search |
||
65 | * A "generic" email address is a role-based email address, like [email protected]. |
||
66 | * On the contrary, a "personal" email address is the address of someone in the company. |
||
67 | * |
||
68 | * @param string $type |
||
69 | * @return DomainSearch |
||
70 | */ |
||
71 | View Code Duplication | public function type(string $type): self |
|
80 | |||
81 | public function make() |
||
95 | } |
||
96 |
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.