Completed
Pull Request — master (#168)
by
unknown
01:49 queued 11s
created

CrawlRequestFulfilledAbstract::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Spatie\Crawler\Handlers;
4
5
use Spatie\Crawler\Crawler;
6
use Spatie\Crawler\CrawlUrl;
7
use Spatie\Crawler\LinkAdder;
8
use Psr\Http\Message\StreamInterface;
9
use Psr\Http\Message\ResponseInterface;
10
11
abstract class CrawlRequestFulfilledAbstract
12
{
13
    /** @var \Spatie\Crawler\Crawler */
14
    protected $crawler;
15
16
    /** @var \Spatie\Crawler\LinkAdder */
17
    protected $linkAdder;
18
19
    public function __construct(Crawler $crawler)
20
    {
21
        $this->crawler = $crawler;
22
23
        $this->linkAdder = new LinkAdder($this->crawler);
24
    }
25
26
    abstract public function __invoke(ResponseInterface $response, $index);
27
28
    protected function handleCrawled(ResponseInterface $response, CrawlUrl $crawlUrl)
29
    {
30
        $this->crawler->getCrawlObservers()->crawled($crawlUrl, $response);
31
    }
32
33
    protected function convertBodyToString(StreamInterface $bodyStream, $readMaximumBytes = 1024 * 1024 * 2): string
34
    {
35
        $bodyStream->rewind();
36
37
        $body = $bodyStream->read($readMaximumBytes);
38
39
        return $body;
40
    }
41
}
42