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

CrawlerRobots   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A mayIndex() 0 9 3
A mayFollow() 0 9 3
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