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

SeparatorSigns::removeFromEnd()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
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