Urlset::addUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 6
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Thepixeldeveloper\Sitemap;
4
5
use XMLWriter;
6
7
/**
8
 * Class Urlset
9
 *
10
 * @package Thepixeldeveloper\Sitemap
11
 */
12 View Code Duplication
class Urlset implements OutputInterface
0 ignored issues
show
Duplication introduced by
This class 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...
13
{
14
    /**
15
     * Array of URL objects.
16
     *
17
     * @var OutputInterface[]
18
     */
19
    protected $urls = [];
20
21
    /**
22
     * Add a new URL object.
23
     *
24
     * @param OutputInterface $url
25
     *
26
     * @return $this
27
     */
28
    public function addUrl(OutputInterface $url)
29
    {
30
        $this->urls[] = $url;
31
32
        return $this;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function generateXML(XMLWriter $XMLWriter)
39
    {
40
        $XMLWriter->startElement('urlset');
41
42
        $XMLWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
43
44
        $XMLWriter->writeAttribute('xsi:schemaLocation',
45
            'http://www.sitemaps.org/schemas/sitemap/0.9 ' .
46
            'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd');
47
48
        $XMLWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
49
50
        foreach ($this->getUrls() as $url) {
51
            $url->generateXML($XMLWriter);
52
        }
53
54
        $XMLWriter->endElement();
55
    }
56
57
    /**
58
     * Get array of URL objects.
59
     * 
60
     * @return OutputInterface[]
61
     */
62
    public function getUrls()
63
    {
64
        return $this->urls;
65
    }
66
}
67