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 |
||
12 | class DomainSearch extends HunterClient |
||
13 | { |
||
14 | /** |
||
15 | * Domain name from which you want to find the email addresses |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | public $domain; |
||
20 | |||
21 | /** |
||
22 | * The company name from which you want to find the email addresses |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | public $company; |
||
27 | |||
28 | /** |
||
29 | * Specifies the max number of email addresses to return |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | public $limit = 0; |
||
34 | |||
35 | /** |
||
36 | * Specifies the number of email addresses to skip |
||
37 | * |
||
38 | * @var int |
||
39 | */ |
||
40 | public $offset = 0; |
||
41 | |||
42 | /** |
||
43 | * Specifies the type of email addresses to return |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | public $type; |
||
48 | |||
49 | /** |
||
50 | * Specifies the selected seniority levels |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | public $seniority = []; |
||
55 | |||
56 | /** |
||
57 | * Specifies the selected departments |
||
58 | * |
||
59 | * @var array |
||
60 | */ |
||
61 | public $department = []; |
||
62 | |||
63 | public function __construct(string $api_key = null) |
||
69 | |||
70 | /** |
||
71 | * Sets domain to search |
||
72 | * |
||
73 | * @param string $domain |
||
74 | * @return DomainSearch |
||
75 | */ |
||
76 | public function domain(string $domain): self |
||
82 | |||
83 | /** |
||
84 | * Set company name to search |
||
85 | * |
||
86 | * @param string $company |
||
87 | * @return DomainSearch |
||
88 | */ |
||
89 | public function company(string $company): self |
||
95 | |||
96 | /** |
||
97 | * Set max number of emails to return. Max 100 |
||
98 | * |
||
99 | * @param int $limit |
||
100 | * @return DomainSearch |
||
101 | */ |
||
102 | public function limit(int $limit): self |
||
108 | |||
109 | /** |
||
110 | * Set the number of email addresses to skip |
||
111 | * |
||
112 | * @param int $offset |
||
113 | * @return DomainSearch |
||
114 | */ |
||
115 | public function offset(int $offset): self |
||
121 | |||
122 | /** |
||
123 | * Set the type of email addresses to include in search |
||
124 | * A "generic" email address is a role-based email address, like [email protected]. |
||
125 | * On the contrary, a "personal" email address is the address of someone in the company. |
||
126 | * |
||
127 | * @param string $type |
||
128 | * @return DomainSearch |
||
129 | */ |
||
130 | View Code Duplication | public function type(string $type): self |
|
139 | |||
140 | /** |
||
141 | * Set the selected seniority levels to include in search |
||
142 | * The possible values are junior, senior or executive. Several seniority levels can be selected |
||
143 | * |
||
144 | * @param string|array $seniority |
||
145 | * @return DomainSearch |
||
146 | */ |
||
147 | public function seniority($seniority): self |
||
155 | |||
156 | /** |
||
157 | * Set the selected departments to include in search |
||
158 | * The possible values are executive, it, finance, management, sales, legal, support, hr, marketing or communication |
||
159 | * |
||
160 | * @param string|array $department |
||
161 | * @return DomainSearch |
||
162 | */ |
||
163 | public function department($department): self |
||
173 | |||
174 | /** |
||
175 | * Build query with set attributes |
||
176 | * |
||
177 | * @return string |
||
178 | * @throws InvalidRequestException |
||
179 | */ |
||
180 | public function make() |
||
199 | } |
||
200 |
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.