Completed
Pull Request — master (#2)
by Jan-Petter
02:43
created

RobotVersionParser::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
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\Client\Directives\RobotVersionClient;
5
use vipnytt\RobotsTxtParser\RobotsTxtInterface;
6
7
/**
8
 * Class RobotVersionParser
9
 *
10
 * @package vipnytt\RobotsTxtParser\Parser\Directives
11
 */
12
class RobotVersionParser implements ParserInterface, RobotsTxtInterface
13
{
14
    /**
15
     * RobotVersion value
16
     * @var float|int|string
17
     */
18
    private $robotVersion;
19
20
    /**
21
     * RobotVersionParser constructor.
22
     */
23
    public function __construct()
24
    {
25
    }
26
27
    /**
28
     * Add
29
     *
30
     * @param float|int|string $line
31
     * @return bool
32
     */
33
    public function add($line)
34
    {
35
        if (!empty($this->robotVersion)) {
36
            return false;
37
        }
38
        $this->robotVersion = $line;
39
        return true;
40
    }
41
42
    /**
43
     * Client
44
     *
45
     * @return RobotVersionClient
46
     */
47
    public function client()
48
    {
49
        return new RobotVersionClient($this->robotVersion);
50
    }
51
52
    /**
53
     * Render
54
     *
55
     * @return string[]
56
     */
57
    public function render()
58
    {
59
        return empty($this->robotVersion) ? [] : [self::DIRECTIVE_ROBOT_VERSION . ':' . $this->robotVersion];
60
    }
61
}
62