PathSanitizer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A removeDoubleSlashes() 0 5 1
A replaceInverseSlashes() 0 9 1
A replaceSeparator() 0 5 2
A sanitize() 0 7 1
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
}