Test Failed
Push — master ( 714803...4d260a )
by Jeroen
04:53 queued 02:16
created

SitemapProvider::getItems()   A

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 0
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\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
            $suffix = array_pop(explode('\\', $this->getKey()));
0 ignored issues
show
Bug introduced by
explode('\', $this->getKey()) cannot be passed to array_pop() as the parameter $array expects a reference. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
            $suffix = array_pop(/** @scrutinizer ignore-type */ explode('\\', $this->getKey()));
Loading history...
34
        }
35
36
        return 'sitemap_' . $suffix;
37
    }
38
39
    public function getKey(): string
40
    {
41
        return $this->key;
42
    }
43
44
    public function createItem(
45
        string $url,
46
        \DateTime $lastModifiedOn,
47
        ChangeFrequency $changeFrequency,
48
        int $priority = 5
49
    ): void {
50
        $this->items->add(new SitemapItem($url, $lastModifiedOn, $changeFrequency, $priority));
51
    }
52
}
53