CommentParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 5 1
A client() 0 4 1
A render() 0 7 2
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\CommentClient;
12
use vipnytt\RobotsTxtParser\Handler\RenderHandler;
13
use vipnytt\RobotsTxtParser\RobotsTxtInterface;
14
15
/**
16
 * Class CommentParser
17
 *
18
 * @package vipnytt\RobotsTxtParser\Parser\Directives
19
 */
20
class CommentParser implements ParserInterface, RobotsTxtInterface
21
{
22
    /**
23
     * User-agent
24
     * @var string
25
     */
26
    private $group;
27
28
    /**
29
     * Comment array
30
     * @var string[]
31
     */
32
    private $comments = [];
33
34
    /**
35
     * Comment constructor.
36
     *
37
     * @param string $group
38
     */
39
    public function __construct($group)
40
    {
41
        $this->group = $group;
42
    }
43
44
    /**
45
     * Add
46
     *
47
     * @param string $line
48
     * @return bool
49
     */
50
    public function add($line)
51
    {
52
        $this->comments[] = $line;
53
        return true;
54
    }
55
56
    /**
57
     * Client
58
     *
59
     * @return CommentClient
60
     */
61
    public function client()
62
    {
63
        return new CommentClient($this->group, $this->comments);
64
    }
65
66
    /**
67
     * Render
68
     *
69
     * @param RenderHandler $handler
70
     * @return bool
71
     */
72
    public function render(RenderHandler $handler)
73
    {
74
        foreach ($this->comments as $comment) {
75
            $handler->add(self::DIRECTIVE_COMMENT, $comment);
76
        }
77
        return true;
78
    }
79
}
80