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; |
||
| 10 | class Crawler extends BaseCrawler implements CrawlerInterface |
||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Selectors to crawler |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | private $selectors = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Get selectors and initialize crawler in HTML |
||
| 21 | * @param string $html |
||
| 22 | * @param array $selectors |
||
| 23 | * @return void |
||
|
|
|||
| 24 | */ |
||
| 25 | public function __construct($html, $selectors) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Verifica antes de fazer o crawler se possui erros |
||
| 34 | * na requisição |
||
| 35 | * @return boolean|null |
||
| 36 | */ |
||
| 37 | public function hasError() |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Extrai informações do HTML através do DOM |
||
| 49 | * |
||
| 50 | * @return array |
||
| 51 | */ |
||
| 52 | View Code Duplication | public function scraping() |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Limpa o valor repassado |
||
| 83 | * @param string $string |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | public function clearString($string) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Filtra selector no crawler |
||
| 93 | */ |
||
| 94 | public function scrap($selector) |
||
| 99 | } |
Adding a
@returnannotation 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.