Completed
Push — master ( dd07bc...4a603a )
by Jan-Petter
05:48
created

Rebuild::getResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace vipnytt\XRobotsTagParser;
4
5
final class Rebuild
6
{
7
    private $directiveArray;
8
    private $reRun = true;
9
10
    /**
11
     * Constructor
12
     *
13
     * @param string $directives
14
     */
15
    public function __construct($directives)
16
    {
17
        $this->directiveArray = $directives;
18
        while ($this->reRun) {
19
            $this->reRun = false;
20
            $this->all();
21
            $this->noindex();
22
            $this->none();
23
            $this->unavailable_after();
24
        }
25
    }
26
27
    /**
28
     * Directive all
29
     *
30
     * @return void
31
     */
32
    private function all()
33
    {
34
        if (!isset($this->directiveArray['all'])) {
35
            return;
36
        }
37
        unset($this->directiveArray['all']);
38
    }
39
40
    /**
41
     * Directive noindex
42
     *
43
     * @return void
44
     */
45 View Code Duplication
    private function noindex()
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...
46
    {
47
        if (!isset($this->directiveArray['noindex'])) {
48
            return;
49
        }
50
        $this->directiveArray['noarchive'] = true;
51
        $this->reRun = true;
52
    }
53
54
    /**
55
     * Directive none
56
     *
57
     * @return void
58
     */
59 View Code Duplication
    private function none()
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...
60
    {
61
        if (!isset($this->directiveArray['none'])) {
62
            return;
63
        }
64
        $this->directiveArray['noindex'] = true;
65
        $this->directiveArray['nofollow'] = true;
66
        $this->reRun = true;
67
    }
68
69
    /**
70
     * Directive unavailable_after
71
     *
72
     * @return void
73
     */
74
    private function unavailable_after()
75
    {
76
        if (
77
            !isset($this->directiveArray['unavailable_after'])
78
            || time() < date_create_from_format(DATE_RFC850, $this->directiveArray['unavailable_after'])
79
        ) {
80
            return;
81
        }
82
        $this->directiveArray['noindex'] = true;
83
        $this->reRun = true;
84
    }
85
86
    /**
87
     * Result
88
     *
89
     * @return array
90
     */
91
    public function getResult()
92
    {
93
        return $this->directiveArray;
94
    }
95
}
96