Sitemap::generateXML()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
namespace Thepixeldeveloper\Sitemap;
4
5
use XMLWriter;
6
7
/**
8
 * Class Sitemap
9
 *
10
 * @package Thepixeldeveloper\Sitemap
11
 */
12
class Sitemap implements OutputInterface
13
{
14
    /**
15
     * Location (URL).
16
     *
17
     * @var string
18
     */
19
    protected $loc;
20
21
    /**
22
     * Last modified time.
23
     *
24
     * @var string
25
     */
26
    protected $lastMod;
27
28
    /**
29
     * Url constructor
30
     *
31
     * @param string $loc
32
     */
33
    public function __construct($loc)
34
    {
35
        $this->loc = $loc;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function generateXML(XMLWriter $XMLWriter)
42
    {
43
        $XMLWriter->startElement('sitemap');
44
        $XMLWriter->writeElement('loc', $this->getLoc());
45
46
        if ($lastMod = $this->getLastMod()) {
47
            $XMLWriter->writeElement('lastmod', $lastMod);
48
        }
49
50
        $XMLWriter->endElement();
51
    }
52
53
    /**
54
     * Get location (URL).
55
     *
56
     * @return string
57
     */
58
    public function getLoc()
59
    {
60
        return $this->loc;
61
    }
62
63
    /**
64
     * Get the last modification time.
65
     *
66
     * @return string|null
67
     */
68
    public function getLastMod()
69
    {
70
        return $this->lastMod;
71
    }
72
73
    /**
74
     * Set the last modification time.
75
     *
76
     * @param string $lastMod
77
     *
78
     * @return $this
79
     */
80
    public function setLastMod($lastMod)
81
    {
82
        $this->lastMod = $lastMod;
83
84
        return $this;
85
    }
86
}
87