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.

Robots::mayFollowOn()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Robots;
4
5
class Robots
6
{
7
    /** @var string|null */
8
    protected $userAgent;
9
10
    /** @var \Spatie\Robots\RobotsTxt|null */
11
    protected $robotsTxt;
12
13
    public function __construct(string $userAgent = null, string $source = null)
14
    {
15
        $this->userAgent = $userAgent;
16
17
        $this->robotsTxt = $source
0 ignored issues
show
Documentation Bug introduced by
It seems like $source ? \Spatie\Robots...eadFrom($source) : null can also be of type object<self>. However, the property $robotsTxt is declared as type object<Spatie\Robots\RobotsTxt>|null. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
18
            ? RobotsTxt::readFrom($source)
19
            : null;
20
    }
21
22
    public function withTxt(string $source): self
23
    {
24
        $this->robotsTxt = RobotsTxt::readFrom($source);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Spatie\Robots\RobotsTxt::readFrom($source) of type object<self> is incompatible with the declared type object<Spatie\Robots\RobotsTxt>|null of property $robotsTxt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
25
26
        return $this;
27
    }
28
29
    public static function create(string $userAgent = null, string $source = null): self
30
    {
31
        return new self($userAgent, $source);
32
    }
33
34
    public function mayIndex(string $url, string $userAgent = null): bool
35
    {
36
        $userAgent = $userAgent ?? $this->userAgent;
37
38
        $robotsTxt = $this->robotsTxt ?? RobotsTxt::create($this->createRobotsUrl($url));
39
40
        return
41
            $robotsTxt->allows($url, $userAgent)
42
            && RobotsMeta::readFrom($url)->mayIndex()
43
            && RobotsHeaders::readFrom($url)->mayIndex();
44
    }
45
46
    public function mayFollowOn(string $url): bool
47
    {
48
        return
49
            RobotsMeta::readFrom($url)->mayFollow()
50
            && RobotsHeaders::readFrom($url)->mayFollow();
51
    }
52
53
    protected function createRobotsUrl(string $url): string
54
    {
55
        $robotsUrl = parse_url($url, PHP_URL_SCHEME).'://'.parse_url($url, PHP_URL_HOST);
56
57
        if ($port = parse_url($url, PHP_URL_PORT)) {
58
            $robotsUrl .= ":{$port}";
59
        }
60
61
        return "{$robotsUrl}/robots.txt";
62
    }
63
}
64