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

Priority   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 35
ccs 7
cts 7
cp 1
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, 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
    public const P9 = '0.9';
18
    public const P8 = '0.8';
19
    public const P7 = '0.7';
20
    public const P6 = '0.6';
21
    public const P5 = '0.5';
22
    public const P4 = '0.4';
23
    public const P3 = '0.3';
24
    public const P2 = '0.2';
25
    public const P1 = '0.1';
26
    public const P0 = '0.0';
27
28
    /**
29
     * @param string $loc
30
     *
31
     * @return string
32
     */
33 36
    public static function getByLoc(string $loc): string
34
    {
35
        // number of slashes
36 36
        $num = count(array_filter(explode('/', trim($loc, '/'))));
37
38 36
        if (!$num) {
39 12
            return '1.0';
40
        }
41
42 24
        if (($p = (10 - $num) / 10) > 0) {
43 20
            return '0.'.($p * 10);
44
        }
45
46 4
        return '0.1';
47
    }
48
}
49