Completed
Pull Request — master (#150)
by Brent
01:28
created

CrawlerRobots::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace Spatie\Crawler;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Spatie\Robots\RobotsHeaders;
7
use Spatie\Robots\RobotsMeta;
8
9
class CrawlerRobots
10
{
11
    /** @var \Spatie\Robots\RobotsHeaders */
12
    protected $robotsHeaders;
13
14
    /** @var \Spatie\Robots\RobotsMeta */
15
    protected $robotsMeta;
16
17
    /** @var bool */
18
    private $mustRespectRobots;
19
20
    public function __construct(ResponseInterface $response, bool $mustRespectRobots)
21
    {
22
        $this->robotsHeaders = RobotsHeaders::create($response->getHeaders());
0 ignored issues
show
Documentation Bug introduced by
It seems like \Spatie\Robots\RobotsHea...response->getHeaders()) of type object<self> is incompatible with the declared type object<Spatie\Robots\RobotsHeaders> of property $robotsHeaders.

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...
23
24
        $this->robotsMeta = RobotsMeta::create((string) $response->getBody());
0 ignored issues
show
Documentation Bug introduced by
It seems like \Spatie\Robots\RobotsMet...) $response->getBody()) of type object<self> is incompatible with the declared type object<Spatie\Robots\RobotsMeta> of property $robotsMeta.

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
        $this->mustRespectRobots = $mustRespectRobots;
27
    }
28
29
    public function mayIndex(): bool
30
    {
31
        if (! $this->mustRespectRobots) {
32
            return true;
33
        }
34
35
        return $this->robotsHeaders->mayIndex()
36
            && $this->robotsMeta->mayIndex();
37
    }
38
39
    public function mayFollow(): bool
40
    {
41
        if (! $this->mustRespectRobots) {
42
            return true;
43
        }
44
45
        return $this->robotsHeaders->mayFollow()
46
            && $this->robotsMeta->mayFollow();
47
    }
48
}
49