CrawlRequestFailed::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Spatie\Crawler\Handlers;
4
5
use Exception;
6
use GuzzleHttp\Exception\RequestException;
7
use Spatie\Crawler\Crawler;
8
9
class CrawlRequestFailed
10
{
11
    /** @var \Spatie\Crawler\Crawler */
12
    protected $crawler;
13
14
    public function __construct(Crawler $crawler)
15
    {
16
        $this->crawler = $crawler;
17
    }
18
19
    public function __invoke(Exception $exception, $index)
20
    {
21
        if ($exception instanceof RequestException) {
22
            $crawlUrl = $this->crawler->getCrawlQueue()->getUrlById($index);
23
24
            $this->crawler->getCrawlObservers()->crawlFailed($crawlUrl, $exception);
25
        }
26
27
        usleep($this->crawler->getDelayBetweenRequests());
28
    }
29
}
30