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\ReceitaFederal\Services\Portais\AN; |
||
12 | class Crawler extends BaseCrawler implements CrawlerInterface |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * Selectors to crawler |
||
17 | * @var array |
||
18 | */ |
||
19 | private $selectors = []; |
||
20 | |||
21 | /** |
||
22 | * Get selectors and initialize crawler in HTML |
||
23 | * @param string $html |
||
24 | * @param array $selectors |
||
25 | * @return void |
||
|
|||
26 | */ |
||
27 | public function __construct($html, $selectors) |
||
33 | |||
34 | /** |
||
35 | * Verifica antes de fazer o crawler se possui erros |
||
36 | * na requisição |
||
37 | * @return boolean|null |
||
38 | */ |
||
39 | public function hasError() |
||
58 | |||
59 | /** |
||
60 | * Extrai informações do HTML através do DOM |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | View Code Duplication | public function scraping() |
|
92 | |||
93 | /** |
||
94 | * Limpa o valor repassado |
||
95 | * @param string $string |
||
96 | * @return string |
||
97 | */ |
||
98 | public function clearString($string) |
||
102 | |||
103 | /** |
||
104 | * Filtra selector no crawler |
||
105 | */ |
||
106 | public function scrap($selector) |
||
111 | } |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.