Passed
Push — master ( ba09bf...91cd83 )
by Bjørn
04:56
created

Sanitize   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 24
ccs 4
cts 8
cp 0.5
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A path() 0 5 1
A removeStreamWrappers() 0 3 1
A removeNUL() 0 3 1
1
<?php
2
3
namespace WebPConvert\Helpers;
4
5
class Sanitize
6
{
7
8
    /**
9
     *  The NUL character is a demon, because it can be used to bypass other tests
10
     *  See https://st-g.de/2011/04/doing-filename-checks-securely-in-PHP.
11
     *
12
     *  @param  string  $string  string remove NUL characters in
13
     */
14 1
    public static function removeNUL($string)
15
    {
16 1
        return str_replace(chr(0), '', $string);
17
    }
18
19 1
    public static function removeStreamWrappers($string)
20
    {
21 1
        return preg_replace('#^\\w+://#', '', $string);
22
    }
23
24
    public static function path($string)
25
    {
26
        $string = self::removeNUL($string);
27
        $string = self::removeStreamWrappers($string);
28
        return $string;
29
    }
30
}
31