SitemapItem::getChangeFrequency()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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
    /**
22
     * @param string $url
23
     * @param \DateTime $lastModifiedOn
24
     * @param ChangeFrequency $changeFrequency
25
     * @param int $priority
26
     * @throws SitemapException
27
     */
28
    public function __construct(
29
        string $url,
30
        \DateTime $lastModifiedOn,
31
        ChangeFrequency $changeFrequency,
32
        int $priority
33
    ) {
34
        $this->url = $url;
35
        $this->lastModifiedOn = $lastModifiedOn;
36
        $this->changeFrequency = $changeFrequency;
37
        $this->setPriority($priority);
38
    }
39
40
    public function getChangeFrequency(): ChangeFrequency
41
    {
42
        return $this->changeFrequency;
43
    }
44
45
    public function getLastModifiedOn(): \DateTime
46
    {
47
        return $this->lastModifiedOn;
48
    }
49
50
    public function getPriority(): int
51
    {
52
        return $this->priority;
53
    }
54
55
    public function getUrl(): string
56
    {
57
        return $this->url;
58
    }
59
60
    /**
61
     * @param int $priority
62
     * @throws SitemapException
63
     */
64
    private function setPriority(int $priority): void
65
    {
66
        if ($priority < 0 || $priority > 10) {
67
            throw SitemapException::forPriority();
68
        }
69
70
        $this->priority = $priority;
71
    }
72
}
73