Completed
Push — master ( 49e9a0...fa7091 )
by Jan-Petter
02:11
created

Sitemap   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 0 11 3
A export() 0 4 2
1
<?php
2
namespace vipnytt\RobotsTxtParser\Modules\Directives;
3
4
use vipnytt\RobotsTxtParser\Modules\UrlTools;
5
use vipnytt\RobotsTxtParser\RobotsTxtInterface;
6
7
/**
8
 * Class Sitemap
9
 *
10
 * @package vipnytt\RobotsTxtParser\Modules\Directives
11
 */
12
class Sitemap implements DirectiveInterface, RobotsTxtInterface
13
{
14
    use UrlTools;
15
16
    /**
17
     * Directive
18
     */
19
    const DIRECTIVE = self::DIRECTIVE_SITEMAP;
20
21
    /**
22
     * Sitemap array
23
     * @var array
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
54
     *
55
     * @return array
56
     */
57
    public function export()
58
    {
59
        return empty($this->array) ? [] : [self::DIRECTIVE => $this->array];
60
    }
61
}
62