Scraper   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 37
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A getCrawler() 0 4 1
A getLongestText() 0 12 3
A returnResult() 0 11 2
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