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

Rebuild   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 18.68 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 12
c 1
b 0
f 1
lcom 1
cbo 0
dl 17
loc 91
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A all() 0 7 2
A noindex() 8 8 2
A none() 9 9 2
A unavailable_after() 0 11 3
A getResult() 0 4 1

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 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