Sitemap   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 64
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addResource() 0 6 1
A getResources() 0 4 1
A validateSitemapResources() 0 8 3
1
<?php
2
declare(strict_types = 1);
3
4
namespace DL\SitemapBundle\Definition;
5
6
use DL\SitemapBundle\Exception\SitemapException;
7
8
/**
9
 * The representation of an entire sitemap collection.
10
 *
11
 * @package DL\SitemapBundle\Definition
12
 * @author  Petre Pătrașc <[email protected]>
13
 */
14
class Sitemap
15
{
16
    /**
17
     * The resources that make up the sitemap collection.
18
     *
19
     * @see SitemapResource
20
     * @var array
21
     */
22
    protected $resources;
23
24
    /**
25
     * Sitemap constructor.
26
     *
27
     * @param array $entries
28
     */
29 8
    public function __construct(array $entries = [])
30
    {
31 8
        $this->validateSitemapResources($entries);
32
33 7
        $this->resources = $entries;
34 7
    }
35
36
    /**
37
     * Add a new sitemap entry into the sitemap collection.
38
     *
39
     * @param SitemapResource $sitemapResource
40
     *
41
     * @return Sitemap
42
     */
43 1
    public function addResource(SitemapResource $sitemapResource): Sitemap
44
    {
45 1
        $this->resources[] = $sitemapResource;
46
47 1
        return $this;
48
    }
49
50
    /**
51
     * Retrieve all of the sitemap resources that have
52
     * been associated to the collection.
53
     *
54
     * @see SitemapResource
55
     * @return array
56
     */
57 3
    public function getResources(): array
58
    {
59 3
        return $this->resources;
60
    }
61
62
    /**
63
     * Validate that an array of sitemap resources is valid.
64
     *
65
     * @param array $sitemapResources
66
     *
67
     * @throws SitemapException
68
     */
69 8
    protected function validateSitemapResources(array $sitemapResources)
70
    {
71 8
        foreach ($sitemapResources as $resource) {
72 2
            if (false === $resource instanceof SitemapResource) {
73 2
                throw new SitemapException('Invalid resource provided for sitemap collection instantiation');
74
            }
75
        }
76 7
    }
77
}
78