Completed
Push — master ( cdf584...500099 )
by Brent
12s
created

MailBrokenLinks::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\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;
0 ignored issues
show
Bug introduced by Brent Roose
Accessing foundOnUrl on the interface Psr\Http\Message\UriInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
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
        return;
75
    }
76
}
77