Completed
Branch 2.0-dev (4f313a)
by Jan-Petter
02:57
created

CommentParser::client()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
namespace vipnytt\RobotsTxtParser\Parser\Directives;
3
4
use vipnytt\RobotsTxtParser\Client\Directives\CommentClient;
5
use vipnytt\RobotsTxtParser\RobotsTxtInterface;
6
7
/**
8
 * Class CommentParser
9
 *
10
 * @package vipnytt\RobotsTxtParser\Parser\Directives
11
 */
12
class CommentParser implements ParserInterface, RobotsTxtInterface
13
{
14
    /**
15
     * Directive
16
     */
17
    const DIRECTIVE = self::DIRECTIVE_COMMENT;
18
19
    /**
20
     * User-agent
21
     * @var string
22
     */
23
    private $userAgent;
24
25
    /**
26
     * Base Uri
27
     * @var string
28
     */
29
    private $base;
30
31
    /**
32
     * Comment array
33
     * @var string[]
34
     */
35
    private $array = [];
36
37
    /**
38
     * Client cache
39
     * @var CommentClient
40
     */
41
    private $client;
42
43
    /**
44
     * Comment constructor.
45
     *
46
     * @param string $base
47
     * @param string $userAgent
48
     */
49
    public function __construct($base, $userAgent)
50
    {
51
        $this->base = $base;
52
        $this->userAgent = $userAgent;
53
    }
54
55
    /**
56
     * Add
57
     *
58
     * @param string $line
59
     * @return bool
60
     */
61
    public function add($line)
62
    {
63
        $this->array[] = $line;
64
        return true;
65
    }
66
67
    /**
68
     * Client
69
     *
70
     * @return CommentClient
71
     */
72
    public function client()
73
    {
74
        if (isset($this->client)) {
75
            return $this->client;
76
        }
77
        return $this->client = new CommentClient($this->base, $this->userAgent, $this->array);
78
    }
79
80
    /**
81
     * Rule array
82
     *
83
     * @return string[][]
84
     */
85
    public function getRules()
86
    {
87
        return empty($this->array) ? [] : [self::DIRECTIVE => $this->array];
88
    }
89
90
    /**
91
     * Render
92
     *
93
     * @return string[]
94
     */
95 View Code Duplication
    public function render()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $result = [];
98
        foreach ($this->array as $value) {
99
            $result[] = self::DIRECTIVE . ':' . $value;
100
        }
101
        return $result;
102
    }
103
}
104