Url   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 61
dl 0
loc 141
rs 10
c 0
b 0
f 0
wmc 23

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getVideos() 0 3 1
A getPriority() 0 3 1
A getLoc() 0 3 1
A getChangefreq() 0 3 1
A getImages() 0 3 1
A setChangefreq() 0 20 2
A addVideo() 0 5 1
A getLastmod() 0 14 4
A setVideos() 0 5 1
A setLoc() 0 9 2
A addImage() 0 5 1
A setImages() 0 5 1
A setLastmod() 0 9 3
A setPriority() 0 11 3
1
<?php
2
3
namespace Sludio\HelperBundle\Sitemap\Entity;
4
5
class Url
6
{
7
    const CHANGEFREQ_ALWAYS = 'always';
8
    const CHANGEFREQ_HOURLY = 'hourly';
9
    const CHANGEFREQ_DAILY = 'daily';
10
    const CHANGEFREQ_WEEKLY = 'weekly';
11
    const CHANGEFREQ_MONTHLY = 'monthly';
12
    const CHANGEFREQ_YEARLY = 'yearly';
13
    const CHANGEFREQ_NEVER = 'never';
14
15
    protected $loc;
16
    protected $lastmod;
17
    protected $changefreq;
18
    protected $priority;
19
    protected $videos = [];
20
    protected $images = [];
21
22
    public function getLoc()
23
    {
24
        return $this->loc;
25
    }
26
27
    public function setLoc($loc)
28
    {
29
        if (\strlen($loc) > 2048) {
30
            throw new \DomainException('The loc value must be less than 2,048 characters');
31
        }
32
33
        $this->loc = $loc;
34
35
        return $this;
36
    }
37
38
    public function getLastmod()
39
    {
40
        if ($this->lastmod === null) {
41
            return null;
42
        }
43
44
        if ($this->getChangefreq() === null || \in_array($this->getChangefreq(), [
45
                self::CHANGEFREQ_ALWAYS,
46
                self::CHANGEFREQ_HOURLY,
47
            ], true)) {
48
            return $this->lastmod->format(\DateTime::W3C);
49
        }
50
51
        return $this->lastmod->format('Y-m-d');
52
    }
53
54
    public function setLastmod($lastmod)
55
    {
56
        if ($lastmod !== null && !$lastmod instanceof \DateTime) {
57
            $lastmod = new \DateTime($lastmod);
58
        }
59
60
        $this->lastmod = $lastmod;
61
62
        return $this;
63
    }
64
65
    public function getChangefreq()
66
    {
67
        return $this->changefreq;
68
    }
69
70
    public function setChangefreq($changefreq)
71
    {
72
        $validFreqs = [
73
            self::CHANGEFREQ_ALWAYS,
74
            self::CHANGEFREQ_HOURLY,
75
            self::CHANGEFREQ_DAILY,
76
            self::CHANGEFREQ_WEEKLY,
77
            self::CHANGEFREQ_MONTHLY,
78
            self::CHANGEFREQ_YEARLY,
79
            self::CHANGEFREQ_NEVER,
80
            null,
81
        ];
82
83
        if (!\in_array($changefreq, $validFreqs, true)) {
84
            throw new \DomainException(sprintf('Invalid changefreq given. Valid values are: %s', implode(', ', $validFreqs)));
85
        }
86
87
        $this->changefreq = $changefreq;
88
89
        return $this;
90
    }
91
92
    public function getPriority()
93
    {
94
        return $this->priority;
95
    }
96
97
    public function setPriority($priority)
98
    {
99
        $priority = (float)$priority;
100
101
        if ($priority < 0 || $priority > 1) {
102
            throw new \DomainException('The priority must be between 0 and 1');
103
        }
104
105
        $this->priority = $priority;
106
107
        return $this;
108
    }
109
110
    public function addVideo(Video $video)
111
    {
112
        $this->videos[] = $video;
113
114
        return $this;
115
    }
116
117
    public function getVideos()
118
    {
119
        return $this->videos;
120
    }
121
122
    public function setVideos($videos)
123
    {
124
        $this->videos = $videos;
125
126
        return $this;
127
    }
128
129
    public function addImage(Image $image)
130
    {
131
        $this->images[] = $image;
132
133
        return $this;
134
    }
135
136
    public function getImages()
137
    {
138
        return $this->images;
139
    }
140
141
    public function setImages($images)
142
    {
143
        $this->images = $images;
144
145
        return $this;
146
    }
147
}
148