Completed
Push — master ( a6d8dc...680f8e )
by Jan-Petter
03:57
created

Sitemap::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 8
loc 8
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
namespace vipnytt\RobotsTxtParser\Parser\Directives;
3
4
use vipnytt\RobotsTxtParser\Parser\RobotsTxtInterface;
5
use vipnytt\RobotsTxtParser\Parser\UrlParser;
6
7
/**
8
 * Class Sitemap
9
 *
10
 * @package vipnytt\RobotsTxtParser\Parser\Directives
11
 */
12
class Sitemap implements DirectiveInterface, RobotsTxtInterface
13
{
14
    use UrlParser;
15
16
    /**
17
     * Directive
18
     */
19
    const DIRECTIVE = self::DIRECTIVE_SITEMAP;
20
21
    /**
22
     * Sitemap array
23
     * @var string[]
24
     */
25
    protected $array = [];
26
27
    /**
28
     * Sitemap constructor.
29
     */
30
    public function __construct()
31
    {
32
    }
33
34
    /**
35
     * Add
36
     *
37
     * @param string $line
38
     * @return bool
39
     */
40
    public function add($line)
41
    {
42
        if (
43
            !$this->urlValidate(($url = $this->urlEncode($line))) ||
44
            in_array($url, $this->array)
45
        ) {
46
            return false;
47
        }
48
        $this->array[] = $url;
49
        return true;
50
    }
51
52
    /**
53
     * Export rules
54
     *
55
     * @return string[][]
56
     */
57
    public function export()
58
    {
59
        return empty($this->array) ? [] : [self::DIRECTIVE => $this->array];
60
    }
61
62
    /**
63
     * Render
64
     *
65
     * @return string[]
66
     */
67 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...
68
    {
69
        $result = [];
70
        foreach ($this->array as $value) {
71
            $result[] = self::DIRECTIVE . ': ' . $value;
72
        }
73
        return $result;
74
    }
75
}
76