Test Failed
Pull Request — master (#5)
by Jeroen
03:08
created

SitemapProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getItems() 0 3 1
A createItem() 0 7 1
A getKey() 0 3 1
A getFilename() 0 9 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
            $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