Passed
Push — master ( cd504b...48cb3c )
by Petr
07:41
created

SeparatorSigns   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A removeFromEnd() 0 4 2
A removeFromStart() 0 4 2
1
<?php
2
3
namespace kalanis\kw_storage\Extras;
4
5
6
/**
7
 * Trait TRemoveCycle
8
 * @package kalanis\kw_storage\Extras
9
 * low-level work with extended dirs - remove dirs and files in cycle - everything with subdirectories
10
 */
11
class SeparatorSigns
12
{
13
    /**
14
     * Remove separator sign from path end
15
     * @param string $path
16
     * @param string $separator
17
     * @return string
18
     */
19 3
    public static function removeFromEnd(string $path, string $separator = DIRECTORY_SEPARATOR): string
20
    {
21 3
        $signLen = mb_strlen($separator);
22 3
        return ($separator == mb_substr($path, -1 * $signLen)) ? mb_substr($path, 0, -1 * $signLen) : $path ;
23
    }
24
25
    /**
26
     * Remove separator sign from path start
27
     * @param string $path
28
     * @param string $separator
29
     * @return string
30
     */
31 3
    public static function removeFromStart(string $path, string $separator = DIRECTORY_SEPARATOR): string
32
    {
33 3
        $signLen = mb_strlen($separator);
34 3
        return ($separator == mb_substr($path, 0, $signLen)) ? mb_substr($path, $signLen) : $path ;
35
    }
36
}
37