Completed
Pull Request — master (#13)
by Peter
06:35
created

SmartUrl::getPriorityFromLoc()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 7
cts 7
cp 1
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * GpsLab component.
6
 *
7
 * @author    Peter Gribanov <[email protected]>
8
 * @copyright Copyright (c) 2011-2019, 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 37
     * @param string|null             $priority
21
     */
22
    public function __construct(
23 37
        string $loc,
24 18
        ?\DateTimeInterface $last_mod = null,
25
        ?string $change_freq = null,
26
        ?string $priority = null
27
    ) {
28 37
        // priority from loc
29 3
        if (!$priority) {
30
            $priority = Priority::getByLoc($loc);
31
        }
32
33 37
        // change freq from last mod
34 28
        if (!$change_freq && $last_mod instanceof \DateTimeInterface) {
35
            $change_freq = ChangeFreq::getByLastMod($last_mod);
36
        }
37 37
38 37
        // change freq from priority
39
        if (!$change_freq) {
40
            $change_freq = ChangeFreq::getByPriority($priority);
41
        }
42
43
        parent::__construct($loc, $last_mod, $change_freq, $priority);
44
    }
45
}
46