SitemapProvider::createItem()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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