Passed
Push — master ( 24a07b...1d6712 )
by Jeroen
03:09
created

SitemapItem::getLastModifiedOn()   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\Item;
4
5
use JeroenDesloovere\SitemapBundle\Exception\SitemapException;
6
7
class SitemapItem
8
{
9
    /** @var ChangeFrequency */
10
    private $changeFrequency;
11
12
    /** @var \DateTime */
13
    private $lastModifiedOn;
14
15
    /** @var int - Value between 0 and 10, will be divided by 10 */
16
    private $priority = 10;
17
18
    /** @var string */
19
    private $url;
20
21
    public function __construct(
22
        string $url,
23
        \DateTime $lastModifiedOn,
24
        ChangeFrequency $changeFrequency,
25
        int $priority = 5
26
    ) {
27
        $this->url = $url;
28
        $this->lastModifiedOn = $lastModifiedOn;
29
        $this->changeFrequency = $changeFrequency;
30
        $this->setPriority($priority);
31
    }
32
33
    public function getChangeFrequency(): ChangeFrequency
34
    {
35
        return $this->changeFrequency;
36
    }
37
38
    public function getLastModifiedOn(): \DateTime
39
    {
40
        return $this->lastModifiedOn;
41
    }
42
43
    public function getPriority(): int
44
    {
45
        return $this->priority;
46
    }
47
48
    public function getUrl(): string
49
    {
50
        return $this->url;
51
    }
52
53
    /**
54
     * @param int $priority
55
     * @throws SitemapException
56
     */
57
    private function setPriority(int $priority): void
58
    {
59
        if ($priority < 0 || $priority > 10) {
60
            throw SitemapException::forPriority();
61
        }
62
63
        $this->priority = $priority;
64
    }
65
}
66