GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LogBrokenLinks   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 77
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A finishedCrawling() 0 21 3
A crawlFailed() 0 17 2
A formatLogMessage() 0 17 2
1
<?php
2
3
namespace Spatie\LinkChecker\Reporters;
4
5
use GuzzleHttp\Exception\RequestException;
6
use Psr\Http\Message\UriInterface;
7
use Psr\Log\LoggerInterface;
8
9
class LogBrokenLinks extends BaseReporter
10
{
11
    protected $log;
12
13
    public function __construct(LoggerInterface $log)
14
    {
15
        $this->log = $log;
16
    }
17
18
    /**
19
     * Called when the crawl has ended.
20
     */
21
    public function finishedCrawling()
22
    {
23
        $this->log->info('link checker summary');
24
25
        collect($this->urlsGroupedByStatusCode)
26
            ->each(function ($urls, $statusCode) {
27
                if ($this->isSuccessOrRedirect($statusCode)) {
28
                    return;
29
                }
30
31
                $count = count($urls);
32
33
                if ($statusCode == static::UNRESPONSIVE_HOST) {
34
                    $this->log->warning("{$count} url(s) did have unresponsive host(s)");
35
36
                    return;
37
                }
38
39
                $this->log->warning("Crawled {$count} url(s) with statuscode {$statusCode}");
40
            });
41
    }
42
43
    /**
44
     * Called when the crawler had a problem crawling the given url.
45
     *
46
     * @param \Psr\Http\Message\UriInterface         $url
47
     * @param \GuzzleHttp\Exception\RequestException $requestException
48
     * @param \Psr\Http\Message\UriInterface|null    $foundOnUrl
49
     */
50
    public function crawlFailed(
51
        UriInterface $url,
52
        RequestException $requestException,
53
        ?UriInterface $foundOnUrl = null
54
    ) {
55
        parent::crawlFailed($url, $requestException, $foundOnUrl);
56
57
        $statusCode = $requestException->getCode();
58
59
        if ($this->isExcludedStatusCode($statusCode)) {
60
            return;
61
        }
62
63
        $this->log->warning(
64
            $this->formatLogMessage($url, $requestException, $foundOnUrl)
65
        );
66
    }
67
68
    protected function formatLogMessage(
69
        UriInterface $url,
70
        RequestException $requestException,
71
        ?UriInterface $foundOnUrl = null
72
    ): string {
73
        $statusCode = $requestException->getCode();
74
75
        $reason = $requestException->getMessage();
76
77
        $logMessage = "{$statusCode} {$reason} - {$url}";
78
79
        if ($foundOnUrl) {
80
            $logMessage .= " (found on {$foundOnUrl}";
81
        }
82
83
        return $logMessage;
84
    }
85
}
86