|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Spatie\LinkChecker\Reporters; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Exception\RequestException; |
|
6
|
|
|
use Illuminate\Contracts\Mail\Mailer; |
|
7
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
8
|
|
|
use Psr\Http\Message\UriInterface; |
|
9
|
|
|
|
|
10
|
|
|
class MailBrokenLinks extends BaseReporter |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Mailer |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $mail; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* MailBrokenLinks constructor. |
|
19
|
|
|
* |
|
20
|
|
|
* @param \Illuminate\Contracts\Mail\Mailer $mail |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct(Mailer $mail) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->mail = $mail; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Called when the crawl has ended. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function finishedCrawling() |
|
31
|
|
|
{ |
|
32
|
|
|
if (! $this->crawledBadUrls()) { |
|
33
|
|
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$urlsGroupedByStatusCode = $this->urlsGroupedByStatusCode; |
|
37
|
|
|
|
|
38
|
|
|
$this->mail->send('laravel-link-checker::crawlReport', compact('urlsGroupedByStatusCode'), function ($message) { |
|
39
|
|
|
$message->from(config('laravel-link-checker.reporters.mail.from_address')); |
|
40
|
|
|
$message->to(config('laravel-link-checker.reporters.mail.to_address')); |
|
41
|
|
|
$message->subject(config('laravel-link-checker.reporters.mail.subject')); |
|
42
|
|
|
}); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Called when the crawler has crawled the given url successfully. |
|
47
|
|
|
* |
|
48
|
|
|
* @param \Psr\Http\Message\UriInterface $url |
|
49
|
|
|
* @param \Psr\Http\Message\ResponseInterface $response |
|
50
|
|
|
* @param \Psr\Http\Message\UriInterface|null $foundOnUrl |
|
51
|
|
|
*/ |
|
52
|
|
|
public function crawled( |
|
53
|
|
|
UriInterface $url, |
|
54
|
|
|
ResponseInterface $response, |
|
55
|
|
|
?UriInterface $foundOnUrl = null |
|
56
|
|
|
) { |
|
57
|
|
|
$url->foundOnUrl = $foundOnUrl; |
|
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
return parent::crawled($url, $response, $foundOnUrl); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Called when the crawler had a problem crawling the given url. |
|
64
|
|
|
* |
|
65
|
|
|
* @param \Psr\Http\Message\UriInterface $url |
|
66
|
|
|
* @param \GuzzleHttp\Exception\RequestException $requestException |
|
67
|
|
|
* @param \Psr\Http\Message\UriInterface|null $foundOnUrl |
|
68
|
|
|
*/ |
|
69
|
|
|
public function crawlFailed( |
|
70
|
|
|
UriInterface $url, |
|
71
|
|
|
RequestException $requestException, |
|
72
|
|
|
?UriInterface $foundOnUrl = null |
|
73
|
|
|
) { |
|
74
|
|
|
$url->foundOnUrl = $foundOnUrl; |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
return parent::crawlFailed($url, $requestException, $foundOnUrl); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: