CrawlerRobots   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 59.26 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 32
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A mayIndex() 16 16 4
A mayFollow() 16 16 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    protected $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 View Code Duplication
    public function mayIndex(): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        if (! $this->mustRespectRobots) {
32
            return true;
33
        }
34
35
        if (! $this->robotsHeaders->mayIndex()) {
36
            return false;
37
        }
38
39
        if (! $this->robotsMeta->mayIndex()) {
40
            return false;
41
        }
42
43
        return true;
44
    }
45
46 View Code Duplication
    public function mayFollow(): bool
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
47
    {
48
        if (! $this->mustRespectRobots) {
49
            return true;
50
        }
51
52
        if (! $this->robotsHeaders->mayFollow()) {
53
            return false;
54
        }
55
56
        if (! $this->robotsMeta->mayFollow()) {
57
            return false;
58
        }
59
60
        return true;
61
    }
62
}
63