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.
Completed
Push — master ( 27b423...5482a6 )
by Sebastian
01:19 queued 11s
created

Observer::normalizePath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\Export\Crawler;
4
5
use Illuminate\Support\Str;
6
use Spatie\Export\Destination;
7
use Spatie\Crawler\CrawlObserver;
8
use Psr\Http\Message\UriInterface;
9
use Psr\Http\Message\ResponseInterface;
10
use GuzzleHttp\Exception\RequestException;
11
12
class Observer extends CrawlObserver
13
{
14
    /** @var string */
15
    protected $entry;
16
17
    /** @var \Spatie\Export\Destination */
18
    protected $destination;
19
20
    public function __construct(string $entry, Destination $destination)
21
    {
22
        $this->entry = $entry;
23
        $this->destination = $destination;
24
    }
25
26
    public function crawled(UriInterface $url, ResponseInterface $response, ?UriInterface $foundOnUrl = null)
27
    {
28
        $contents = str_replace($this->entry.'/', '/', (string) $response->getBody());
29
        $contents = str_replace($this->entry, '/', $contents);
30
31
        $this->destination->write(
32
            $this->normalizePath($url->getPath()),
33
            $contents
34
        );
35
    }
36
37
    public function crawlFailed(UriInterface $url, RequestException $requestException, ?UriInterface $foundOnUrl = null)
38
    {
39
        throw $requestException;
40
    }
41
42
    protected function normalizePath(string $path)
43
    {
44
        if (! Str::contains(basename($path), '.')) {
45
            $path .= '/index.html';
46
        }
47
48
        return ltrim($path, '/');
49
    }
50
}
51