SitemapProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 14
c 4
b 0
f 0
dl 0
loc 43
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createItem() 0 7 1
A getKey() 0 3 1
A __construct() 0 4 1
A getItems() 0 3 1
A getFilename() 0 10 2
1
<?php
2
3
namespace JeroenDesloovere\SitemapBundle\Provider;
4
5
use JeroenDesloovere\SitemapBundle\Item\ChangeFrequency;
6
use JeroenDesloovere\SitemapBundle\Item\SitemapItem;
7
use JeroenDesloovere\SitemapBundle\Item\SitemapItems;
8
9
class SitemapProvider
10
{
11
    /** @var SitemapItems */
12
    private $items;
13
14
    /** @var string - bvb: NewsArticle, will create a "sitemap_NewsArticle.xml" file */
15
    private $key;
16
17
    public function __construct(string $key)
18
    {
19
        $this->key = $key;
20
        $this->items = new SitemapItems();
21
    }
22
23
    public function getItems(): SitemapItems
24
    {
25
        return $this->items;
26
    }
27
28
    public function getFilename(): string
29
    {
30
        try {
31
            $suffix = (new \ReflectionClass($this->getKey()))->getShortName();
32
        } catch (\Exception $e) {
33
            $namespaceParts = explode('\\', $this->getKey());
34
            $suffix = array_pop($namespaceParts);
35
        }
36
37
        return 'sitemap_' . $suffix;
38
    }
39
40
    public function getKey(): string
41
    {
42
        return $this->key;
43
    }
44
45
    public function createItem(
46
        string $url,
47
        \DateTime $lastModifiedOn,
48
        ChangeFrequency $changeFrequency,
49
        int $priority = 5
50
    ): void {
51
        $this->items->add(new SitemapItem($url, $lastModifiedOn, $changeFrequency, $priority));
52
    }
53
}
54