Normalizer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 29
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalizePath() 0 21 5
1
<?php
2
namespace Aoe\Asdis\System\Uri;
3
4
class Normalizer
5
{
6
    /**
7
     * Makes a path relative to the webroot.
8
     *
9
     * @param string $path The path.
10
     * @return string
11
     */
12 3
    public function normalizePath($path)
13
    {
14
        // Fix for wildcard protocol URLs, as parse_url (until PHP 5.4.7) requires the protocol to be set
15
        // @see http://www.php.net/manual/en/function.parse-url.php
16 3
        if ('//' === substr($path, 0, 2)) {
17 1
            $path = 'http:' . $path;
18
        }
19
20 3
        $pathInfos = parse_url($path);
21
22 3
        if (isset($pathInfos['path'])) {
23 3
            $path = $pathInfos['path'];
24 3
            if (isset($pathInfos['query'])) {
25
                $path .= '?' . $pathInfos['query'];
26
            }
27
        }
28
29 3
        if (strpos($path, '/') === 0) {
30 1
            $path = substr($path, 1);
31
        }
32 3
        return $path;
33
    }
34
}