Completed
Branch 2.0-dev (d250b8)
by Jan-Petter
03:02
created

VisitTimeParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 0 9 2
A export() 0 4 2
A render() 0 8 2
1
<?php
2
namespace vipnytt\RobotsTxtParser\Parser\Directives;
3
4
use vipnytt\RobotsTxtParser\RobotsTxtInterface;
5
6
/**
7
 * Class VisitTimeParser
8
 *
9
 * @package vipnytt\RobotsTxtParser\Parser\Directives
10
 */
11
class VisitTimeParser implements ParserInterface, RobotsTxtInterface
12
{
13
    use DirectiveParserCommons;
14
15
    /**
16
     * Directive
17
     */
18
    const DIRECTIVE = self::DIRECTIVE_VISIT_TIME;
19
20
    /**
21
     * VisitTime array
22
     * @var array
23
     */
24
    private $array = [];
25
26
    /**
27
     * VisitTime constructor.
28
     */
29
    public function __construct()
30
    {
31
    }
32
33
    /**
34
     * Add
35
     *
36
     * @param string $line
37
     * @return bool
38
     */
39
    public function add($line)
40
    {
41
        $array = $this->draftParseTime($line);
42
        if ($array !== false) {
43
            $this->array[] = $array;
44
            return true;
45
        }
46
        return false;
47
    }
48
49
    /**
50
     * Export rules
51
     *
52
     * @return string[][]
53
     */
54
    public function export()
55
    {
56
        return empty($this->array) ? [] : [self::DIRECTIVE => $this->array];
57
    }
58
59
    /**
60
     * Render
61
     *
62
     * @return string[]
63
     */
64
    public function render()
65
    {
66
        $result = [];
67
        foreach ($this->array as $array) {
68
            $result[] = self::DIRECTIVE . ':' . $array['from'] . '-' . $array['to'];
69
        }
70
        return $result;
71
    }
72
}
73