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

Priority   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 45
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getByLoc() 0 15 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
final class Priority
15
{
16
    public const P10 = '1.0';
17
18
    public const P9 = '0.9';
19
20
    public const P8 = '0.8';
21
22
    public const P7 = '0.7';
23
24
    public const P6 = '0.6';
25
26
    public const P5 = '0.5';
27
28
    public const P4 = '0.4';
29
30
    public const P3 = '0.3';
31
32
    public const P2 = '0.2';
33
34
    public const P1 = '0.1';
35
36
    public const P0 = '0.0';
37
38
    /**
39
     * @param string $loc
40
     *
41
     * @return string
42
     */
43
    public static function getByLoc(string $loc): string
44
    {
45
        // number of slashes
46
        $num = count(array_filter(explode('/', trim($loc, '/'))));
47
48
        if (!$num) {
49
            return '1.0';
50
        }
51
52
        if (($p = (10 - $num) / 10) > 0) {
53
            return '0.'.($p * 10);
54
        }
55
56
        return '0.1';
57
    }
58
}
59