Scraper::getCrawler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Colligator\Scrapers;
4
5
use Goutte\Client;
6
7
class Scraper
8
{
9
    public function __construct(Client $client = null)
10
    {
11
        $this->client = $client ?: new Client();
12
    }
13
14
    public function getCrawler($url)
15
    {
16
        return $this->client->request('GET', $url);
17
    }
18
19
    protected function getLongestText($texts)
20
    {
21
        $longestText = '';
22
        foreach ($texts as $text) {
23
            $text = trim($text);
24
            if (strlen($text) > strlen($longestText)) {
25
                $longestText = $text;
26
            }
27
        }
28
29
        return $longestText;
30
    }
31
32
    protected function returnResult($text, $source)
33
    {
34
        if (strlen($text) < 20) {
35
            throw new ScrapeException(get_class($this));
36
        }
37
38
        return [
39
            'text'   => trim($text),
40
            'source' => trim($source),
41
        ];
42
    }
43
}
44