Url   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 1
dl 0
loc 95
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 5
A getLoc() 0 4 1
A getLastMod() 0 4 1
A getChangeFreq() 0 4 1
A getPriority() 0 4 1
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Component\Sitemap\Url;
11
12
use GpsLab\Component\Sitemap\Url\Exception\LocationTooLongException;
13
14
class Url
15
{
16
    const CHANGE_FREQ_ALWAYS = 'always';
17
18
    const CHANGE_FREQ_HOURLY = 'hourly';
19
20
    const CHANGE_FREQ_DAILY = 'daily';
21
22
    const CHANGE_FREQ_WEEKLY = 'weekly';
23
24
    const CHANGE_FREQ_MONTHLY = 'monthly';
25
26
    const CHANGE_FREQ_YEARLY = 'yearly';
27
28
    const CHANGE_FREQ_NEVER = 'never';
29
30
    const DEFAULT_PRIORITY = '1.0';
31
32
    const DEFAULT_CHANGE_FREQ = self::CHANGE_FREQ_WEEKLY;
33
34
    /**
35
     * The location must be less than 2048 characters.
36
     */
37
    const LOCATION_MAX_LENGTH = 2047;
38
39
    /**
40
     * @var string
41
     */
42
    private $loc;
43
44
    /**
45
     * @var \DateTimeImmutable
46
     */
47
    private $last_mod;
48
49
    /**
50
     * @var string
51
     */
52
    private $change_freq;
53
54
    /**
55
     * @var string
56
     */
57
    private $priority;
58
59
    /**
60
     * @param string                  $loc
61
     * @param \DateTimeImmutable|null $last_mod
62
     * @param string|null             $change_freq
63
     * @param string|null             $priority
64
     */
65 80
    public function __construct($loc, \DateTimeImmutable $last_mod = null, $change_freq = null, $priority = null)
66
    {
67 80
        if (strlen($loc) > self::LOCATION_MAX_LENGTH) {
68 1
            throw LocationTooLongException::longLocation($loc, self::LOCATION_MAX_LENGTH);
69
        }
70
71 79
        $this->loc = $loc;
72 79
        $this->last_mod = $last_mod ?: new \DateTimeImmutable();
73 79
        $this->change_freq = $change_freq ?: self::DEFAULT_CHANGE_FREQ;
74 79
        $this->priority = $priority ?: self::DEFAULT_PRIORITY;
75 79
    }
76
77
    /**
78
     * @return string
79
     */
80 55
    public function getLoc()
81
    {
82 55
        return $this->loc;
83
    }
84
85
    /**
86
     * @return \DateTimeImmutable
87
     */
88 38
    public function getLastMod()
89
    {
90 38
        return $this->last_mod;
91
    }
92
93
    /**
94
     * @return string
95
     */
96 38
    public function getChangeFreq()
97
    {
98 38
        return $this->change_freq;
99
    }
100
101
    /**
102
     * @return string
103
     */
104 48
    public function getPriority()
105
    {
106 48
        return $this->priority;
107
    }
108
}
109