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

Sitemap::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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