| Total Complexity | 9 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class ExtractResults |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var array from \rOpenDev\Google\ResultTypes.php |
||
| 9 | */ |
||
| 10 | protected $types; |
||
| 11 | /** |
||
| 12 | * @var object dom |
||
| 13 | */ |
||
| 14 | protected $html; |
||
| 15 | |||
| 16 | public function __construct(string $source) |
||
| 17 | { |
||
| 18 | $this->html = new \simple_html_dom(); |
||
| 19 | $this->html->load($source); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function getOrganicResults() |
||
| 23 | { |
||
| 24 | $results = $this->html->find(str_replace(';', ', ', $this->getSelector('organic'))); |
||
| 25 | $result = []; |
||
| 26 | foreach ($results as $r) { |
||
| 27 | $title = $r->find('h3, [role=heading]', 0); |
||
| 28 | if ($title) { |
||
| 29 | $result[] = [ |
||
| 30 | 'type' => 'organic', |
||
| 31 | 'title' => $this->normalizeTextFromGoogle($title->innertext), |
||
| 32 | 'link' => $this->getUrlFromGoogleSerpFromat($r->find('a', 0)->href), |
||
| 33 | ]; |
||
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | return $result; |
||
| 38 | } |
||
| 39 | |||
| 40 | protected function getSelector(string $type) |
||
| 47 | } |
||
| 48 | |||
| 49 | protected static function getUrlFromGoogleSerpFromat($str) |
||
| 55 | } |
||
| 56 | |||
| 57 | protected function normalizeTextFromGoogle($text) |
||
| 62 |