RobotVersionParser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * vipnytt/RobotsTxtParser
4
 *
5
 * @link https://github.com/VIPnytt/RobotsTxtParser
6
 * @license https://github.com/VIPnytt/RobotsTxtParser/blob/master/LICENSE The MIT License (MIT)
7
 */
8
9
namespace vipnytt\RobotsTxtParser\Parser\Directives;
10
11
use vipnytt\RobotsTxtParser\Client\Directives\RobotVersionClient;
12
use vipnytt\RobotsTxtParser\Handler\RenderHandler;
13
use vipnytt\RobotsTxtParser\RobotsTxtInterface;
14
15
/**
16
 * Class RobotVersionParser
17
 *
18
 * @package vipnytt\RobotsTxtParser\Parser\Directives
19
 */
20
class RobotVersionParser implements ParserInterface, RobotsTxtInterface
21
{
22
    /**
23
     * RobotVersion value
24
     * @var float|int|string
25
     */
26
    private $version;
27
28
    /**
29
     * RobotVersionParser constructor.
30
     */
31
    public function __construct()
32
    {
33
    }
34
35
    /**
36
     * Add
37
     *
38
     * @param float|int|string $line
39
     * @return bool
40
     */
41
    public function add($line)
42
    {
43
        if (!empty($this->version)) {
44
            return false;
45
        }
46
        $this->version = $line;
47
        return true;
48
    }
49
50
    /**
51
     * Client
52
     *
53
     * @return RobotVersionClient
54
     */
55
    public function client()
56
    {
57
        return new RobotVersionClient($this->version);
58
    }
59
60
    /**
61
     * Render
62
     *
63
     * @param RenderHandler $handler
64
     * @return bool
65
     */
66
    public function render(RenderHandler $handler)
67
    {
68
        if (!empty($this->version)) {
69
            $handler->add(self::DIRECTIVE_ROBOT_VERSION, $this->version);
70
        }
71
        return true;
72
    }
73
}
74