Completed
Pull Request — master (#13)
by Peter
03:22 queued 54s
created

SmartUrl::getChangeFreqFromPriority()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * GpsLab component.
6
 *
7
 * @author    Peter Gribanov <[email protected]>
8
 * @copyright Copyright (c) 2011, Peter Gribanov
9
 * @license   http://opensource.org/licenses/MIT
10
 */
11
12
namespace GpsLab\Component\Sitemap\Url;
13
14
class SmartUrl extends Url
15
{
16
    /**
17
     * @param string                  $loc
18
     * @param \DateTimeInterface|null $last_mod
19
     * @param string|null             $change_freq
20
     * @param string|null             $priority
21
     */
22 49
    public function __construct(
23
        string $loc,
24
        ?\DateTimeInterface $last_mod = null,
25
        ?string $change_freq = null,
26
        ?string $priority = null
27
    ) {
28
        // priority from loc
29 49
        if (!$priority) {
30 23
            $priority = Priority::getByLoc($loc);
31
        }
32
33
        // change freq from last mod
34 49
        if (!$change_freq && $last_mod instanceof \DateTimeInterface) {
35 8
            $change_freq = ChangeFreq::getByLastMod($last_mod);
36
        }
37
38
        // change freq from priority
39 49
        if (!$change_freq) {
40 29
            $change_freq = ChangeFreq::getByPriority($priority);
41
        }
42
43 49
        parent::__construct($loc, $last_mod, $change_freq, $priority);
44 49
    }
45
}
46