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

RobotVersionParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
c 4
b 0
f 0
lcom 1
cbo 1
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A client() 0 4 1
A render() 0 4 2
A add() 0 8 2
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