SitemapIndex   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addSitemap() 6 6 1
A generateXML() 19 19 2
A getSitemaps() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Thepixeldeveloper\Sitemap;
4
5
use XMLWriter;
6
7
/**
8
 * Class SitemapIndex
9
 *
10
 * @package Thepixeldeveloper\Sitemap
11
 */
12 View Code Duplication
class SitemapIndex 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 Sitemap entries.
16
     *
17
     * @var OutputInterface[]
18
     */
19
    protected $sitemaps = [];
20
21
    /**
22
     * Add a new Sitemap object to the collection.
23
     *
24
     * @param OutputInterface $sitemap
25
     *
26
     * @return $this
27
     */
28
    public function addSitemap(OutputInterface $sitemap)
29
    {
30
        $this->sitemaps[] = $sitemap;
31
32
        return $this;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function generateXML(XMLWriter $XMLWriter)
39
    {
40
        $XMLWriter->startElement('sitemapindex');
41
        $XMLWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
42
43
        $XMLWriter->writeAttribute(
44
            'xsi:schemaLocation',
45
            'http://www.sitemaps.org/schemas/sitemap/0.9 ' .
46
            'http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd'
47
        );
48
49
        $XMLWriter->writeAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
50
51
        foreach ($this->getSitemaps() as $sitemap) {
52
            $sitemap->generateXML($XMLWriter);
53
        }
54
55
        $XMLWriter->endElement();
56
    }
57
58
    /**
59
     * Get an array of Sitemap objects.
60
     *
61
     * @return OutputInterface[]
62
     */
63
    public function getSitemaps()
64
    {
65
        return $this->sitemaps;
66
    }
67
}
68