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

VisitTimeParser::export()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 0
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