SitemapProviders   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A exists() 0 3 1
A getKeys() 0 3 1
A add() 0 3 1
A getAll() 0 3 1
1
<?php
2
3
namespace JeroenDesloovere\SitemapBundle\Provider;
4
5
use JeroenDesloovere\SitemapBundle\Exception\SitemapException;
6
7
class SitemapProviders
8
{
9
    /** @var SitemapProviderInterface[] */
10
    private $sitemapProviders = [];
11
12
    public function add(SitemapProviderInterface $sitemapProvider): void
13
    {
14
        $this->sitemapProviders[$sitemapProvider->getKey()] = $sitemapProvider;
15
    }
16
17
    public function exists(string $sitemapProviderKey): bool
18
    {
19
        return array_key_exists($sitemapProviderKey, $this->sitemapProviders);
20
    }
21
22
    /**
23
     * @param string $sitemapProviderKey
24
     * @return SitemapProviderInterface
25
     * @throws SitemapException
26
     */
27
    public function get(string $sitemapProviderKey): SitemapProviderInterface
28
    {
29
        if (!$this->exists($sitemapProviderKey)) {
30
            throw SitemapException::forNotExistingSitemapProvider($sitemapProviderKey);
31
        }
32
33
        return $this->sitemapProviders[$sitemapProviderKey];
34
    }
35
36
    public function getAll(): array
37
    {
38
        return $this->sitemapProviders;
39
    }
40
41
    public function getKeys(): array
42
    {
43
        return array_keys($this->sitemapProviders);
44
    }
45
}
46