SitemapProviders::exists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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