PathSanitizer::replaceSeparator()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Maestriam\FileSystem\Foundation\Drive;
4
5
abstract class PathSanitizer
6
{    
7
    /**
8
     * Ajusta uma string de caminho para 
9
     *
10
     * @param string $path
11
     * @return string
12
     */
13
    public static function sanitize(string $path) : string
14
    {
15
        $path = self::replaceSeparator($path);
16
        $path = self::removeDoubleSlashes($path);
17
        $path = self::replaceInverseSlashes($path);
18
        
19
        return $path;
20
    }
21
22
    private static function replaceSeparator(string $path) : string
23
    {
24
        $anti = (DS == '/') ? '\\' : '/';
25
26
        return str_replace($anti, DS, $path);
27
    }
28
29
    private static function removeDoubleSlashes(string $path) : string
30
    {
31
        $search = DS . DS;
32
33
        return str_replace($search, DS, $path);
34
    }
35
36
    private static function replaceInverseSlashes(string $path) : string
37
    {
38
        $anti = '/\\';
39
        $path = str_replace($anti, DS, $path);
40
        
41
        $anti = '\//';
42
        $path = str_replace($anti, DS, $path);
43
44
        return $path;
45
    }
46
}