Completed
Push — master ( a7ec5f...7812c9 )
by Jan-Petter
02:03
created

Sitemap   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
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 40
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 11 3
A export() 0 4 2
1
<?php
2
namespace vipnytt\RobotsTxtParser\Directives;
3
4
use vipnytt\RobotsTxtParser\UrlToolbox;
5
6
/**
7
 * Class Sitemap
8
 *
9
 * @package vipnytt\RobotsTxtParser\Directives
10
 */
11
class Sitemap implements DirectiveInterface
12
{
13
    use UrlToolbox;
14
15
    /**
16
     * Directive
17
     */
18
    const DIRECTIVE = 'Sitemap';
19
20
    protected $parent;
21
    protected $array = [];
22
23
    public function __construct($array, $parent = null)
24
    {
25
        $this->array = $array;
0 ignored issues
show
Documentation Bug introduced by
It seems like $array of type string is incompatible with the declared type array of property $array.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26
    }
27
28
    /**
29
     * Add
30
     *
31
     * @param string $line
32
     * @return bool
33
     */
34
    public function add($line)
35
    {
36
        if (
37
            !$this->urlValidate(($url = $this->urlEncode($line))) ||
38
            in_array($url, $this->array)
39
        ) {
40
            return false;
41
        }
42
        $this->array[] = $url;
43
        return true;
44
    }
45
46
    public function export()
47
    {
48
        return empty($this->array) ? [] : [self::DIRECTIVE => $this->array];
49
    }
50
}
51