Completed
Push — master ( 5d7abd...b7bd87 )
by Brent
10:20
created

Observer::crawlFailed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
namespace Spatie\Sitemap\Crawler;
4
5
use GuzzleHttp\Exception\RequestException;
6
use Psr\Http\Message\ResponseInterface;
7
use Spatie\Crawler\CrawlObserver;
8
use Psr\Http\Message\UriInterface;
9
10
class Observer extends CrawlObserver
11
{
12
    /** @var callable */
13
    protected $hasCrawled;
14
15
    public function __construct(callable $hasCrawled)
16
    {
17
        $this->hasCrawled = $hasCrawled;
18
    }
19
20
    /**
21
     * Called when the crawler will crawl the url.
22
     *
23
     * @param \Psr\Http\Message\UriInterface $url
24
     */
25
    public function willCrawl(UriInterface $url)
26
    {
27
    }
28
29
    /**
30
     * Called when the crawl has ended.
31
     */
32
    public function finishedCrawling()
33
    {
34
    }
35
36
    /**
37
     * Called when the crawler has crawled the given url successfully.
38
     *
39
     * @param \Psr\Http\Message\UriInterface      $url
40
     * @param \Psr\Http\Message\ResponseInterface $response
41
     * @param \Psr\Http\Message\UriInterface|null $foundOnUrl
42
     */
43
    public function crawled(
44
        UriInterface $url,
45
        ResponseInterface $response,
46
        ?UriInterface $foundOnUrl = null
47
    ) {
48
        ($this->hasCrawled)($url, $response);
49
    }
50
51
    /**
52
     * Called when the crawler had a problem crawling the given url.
53
     *
54
     * @param \Psr\Http\Message\UriInterface         $url
55
     * @param \GuzzleHttp\Exception\RequestException $requestException
56
     * @param \Psr\Http\Message\UriInterface|null    $foundOnUrl
57
     */
58
    public function crawlFailed(
59
        UriInterface $url,
60
        RequestException $requestException,
61
        ?UriInterface $foundOnUrl = null
62
    ) {
63
        return;
64
    }
65
}
66