Completed
Push — master ( 4a603a...3189f8 )
by Jan-Petter
02:42
created

Rebuild   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 14
c 2
b 1
f 1
lcom 1
cbo 0
dl 0
loc 98
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parse() 0 11 2
A all() 0 7 2
A noindex() 0 7 2
A none() 0 8 2
A unavailable_after() 0 10 4
A getResult() 0 4 1
1
<?php
2
3
namespace vipnytt\XRobotsTagParser;
4
5
final class Rebuild
6
{
7
    private $directiveArray;
8
9
    /**
10
     * Constructor
11
     *
12
     * @param string $directives
13
     */
14
    public function __construct($directives)
15
    {
16
        $this->directiveArray = $directives;
17
        $this->parse();
18
    }
19
20
    /**
21
     * parse
22
     *
23
     * @return void
24
     */
25
    private function parse()
26
    {
27
        $past = [];
28
        while ($past !== $this->directiveArray) {
29
            $past = $this->directiveArray;
30
            $this->all();
31
            $this->noindex();
32
            $this->none();
33
            $this->unavailable_after();
34
        }
35
    }
36
37
    /**
38
     * Directive all
39
     *
40
     * @return void
41
     */
42
    private function all()
43
    {
44
        if (!isset($this->directiveArray['all'])) {
45
            return;
46
        }
47
        unset($this->directiveArray['all']);
48
    }
49
50
    /**
51
     * Directive noindex
52
     *
53
     * @return void
54
     */
55
    private function noindex()
56
    {
57
        if (!isset($this->directiveArray['noindex'])) {
58
            return;
59
        }
60
        $this->directiveArray['noarchive'] = true;
61
    }
62
63
    /**
64
     * Directive none
65
     *
66
     * @return void
67
     */
68
    private function none()
69
    {
70
        if (!isset($this->directiveArray['none'])) {
71
            return;
72
        }
73
        $this->directiveArray['noindex'] = true;
74
        $this->directiveArray['nofollow'] = true;
75
    }
76
77
    /**
78
     * Directive unavailable_after
79
     *
80
     * @return void
81
     */
82
    private function unavailable_after()
83
    {
84
        if (!isset($this->directiveArray['unavailable_after'])) {
85
            return;
86
        }
87
        $dateTime = date_create_from_format(DATE_RFC850, $this->directiveArray['unavailable_after']);
88
        if ($dateTime !== false && time() >= $dateTime->getTimestamp()) {
89
            $this->directiveArray['noindex'] = true;
90
        }
91
    }
92
93
    /**
94
     * Result
95
     *
96
     * @return array
97
     */
98
    public function getResult()
99
    {
100
        return $this->directiveArray;
101
    }
102
}
103