Helper   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 38
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A appendSlashes() 0 8 2
A getTrailingSlashes() 0 11 3
1
<?php
2
3
namespace Sulao\LRTS;
4
5
class Helper
6
{
7
    /**
8
     * Append trail slashes
9
     *
10
     * @param string $path   the path to append trail slashes
11
     * @param string $origin the origin path with trail slashes
12
     *
13
     * @return string
14
     */
15
    public static function appendSlashes($path, $origin)
16
    {
17
        if ($path !== $origin) {
18
            $slash = self::getTrailingSlashes($origin);
19
            return rtrim($path, '/') . $slash;
20
        }
21
22
        return $path;
23
    }
24
25
    /**
26
     * Get trailing slashes
27
     *
28
     * @param string $path
29
     *
30
     * @return string
31
     */
32
    public static function getTrailingSlashes($path)
33
    {
34
        $slash = '';
35
        $offset = -1;
36
        $len = strlen($path);
37
        while ($len >= abs($offset) && substr($path, $offset, 1) === '/') {
38
            $slash .= '/';
39
            $offset -= 1;
40
        }
41
42
        return $slash;
43
    }
44
}
45