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 namespace zServices\Sintegra\Services\Portais\SP; |
||
16 | class Search implements SearchInterface { |
||
17 | /** |
||
18 | * Armazena a instãncia atual do request no serviço |
||
19 | * @var object |
||
20 | */ |
||
21 | private $instanceResponse; |
||
22 | |||
23 | /** |
||
24 | * Armazena o cookie atual |
||
25 | * @var string |
||
26 | */ |
||
27 | private $cookie; |
||
28 | |||
29 | /** |
||
30 | * Captcha request response |
||
31 | * @var string |
||
32 | */ |
||
33 | private $captcha; |
||
34 | |||
35 | /** |
||
36 | * Armazena o base64 da imagem do captcha |
||
37 | * @var string base64 |
||
38 | */ |
||
39 | private $captchaImage; |
||
40 | |||
41 | /** |
||
42 | * @var object zServices\Sintegra\Services\ClientHttp |
||
43 | */ |
||
44 | private $client; |
||
45 | |||
46 | /** |
||
47 | * Armazena as configurações para as requisições e crawler |
||
48 | * @var array |
||
49 | */ |
||
50 | private $configurations; |
||
51 | |||
52 | /** |
||
53 | * [$params description] |
||
54 | * @var array |
||
55 | */ |
||
56 | private $params = []; |
||
57 | |||
58 | /** |
||
59 | * decaptcher instance |
||
60 | * @var \Captcha\Interfaces\ServiceInterface |
||
61 | */ |
||
62 | public $decaptcher; |
||
63 | |||
64 | /** |
||
65 | * Antes de chamar o cookie e o captcha, é preciso efetuar uma requisição |
||
66 | * primária no serviço. Capturando tais informações. |
||
67 | * Este método deverá fazer essa requisição, armazenando o request |
||
68 | * para os método como cookie e captcha prepararem suas informações |
||
69 | * |
||
70 | * @param array $configurations @ref zServices\Sintegra\Services\Sintegra\{Service}\Service::$configurations |
||
71 | * @return Search |
||
72 | */ |
||
73 | View Code Duplication | public function request($configurations) { |
|
87 | |||
88 | /** |
||
89 | * Verifica se existe existencia de request |
||
90 | * @return boolean |
||
91 | */ |
||
92 | private function hasRequested() { |
||
99 | |||
100 | /** |
||
101 | * Retorna o captcha do serviço para o usuário |
||
102 | * @return string base64_image |
||
103 | */ |
||
104 | public function getCaptcha() { |
||
177 | |||
178 | /** |
||
179 | * Retorna o cookie da requisição para as |
||
180 | * próximas requisições |
||
181 | * @return string $cookie |
||
182 | */ |
||
183 | public function getCookie() { |
||
188 | |||
189 | /** |
||
190 | * Alguns serviços possuem outros parametros. |
||
191 | * Como por exemplo o serviço de SP. |
||
192 | * No formulário possui o input "parambot" |
||
193 | * e nas requisições posteriores é preciso enviá-lo. |
||
194 | * |
||
195 | * Este método irá buscar no crawler estes parametros avulsos. |
||
196 | * @return array $params |
||
197 | */ |
||
198 | public function getParams() { |
||
203 | |||
204 | /** |
||
205 | * ServiceInterface from decaptcher |
||
206 | * |
||
207 | * Impoe o serviço a ser utilizado para efetuar a quebra do captcha |
||
208 | * @param ServiceInterface $decaptcher |
||
209 | * @return Search |
||
210 | */ |
||
211 | public function decaptcher(ServiceInterface $decaptcher) { |
||
216 | |||
217 | /** |
||
218 | * Implement decaptcher |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | private function resolveCaptcha($captchImageOrtxt) { |
||
230 | |||
231 | /** |
||
232 | * Retorna as informações da empresa/pessoa consultada. |
||
233 | * @param integer $document Documento de identificação da entidade |
||
234 | * @param string $cookie Referencia: $service->cookie() |
||
235 | * @param string $captcha Texto do captcha resolvido pelo usuário ou base64 |
||
236 | * @param array $params Parametros avulsos de requisição. Referência $service->params() |
||
237 | * @return Crawler $data Informações da entidade no serviço. |
||
238 | */ |
||
239 | public function getData($document, $cookie, $captcha, $params, $configurations) { |
||
299 | } |
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.