Passed
Push — master ( 6df11d...8e8817 )
by Julien
05:21
created

Url   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 49
ccs 19
cts 19
cp 1
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 3 1
B getAbsolutePath() 0 27 7
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc;
13
14
/**
15
 * {@inheritDoc}
16
 */
17
class Url extends \Phalcon\Mvc\Url
18
{
19
    /**
20
     * {@inheritdoc}
21
     *
22
     * @param array|string|null $uri
23
     * @param mixed $args
24
     * @param bool|null $local
25
     * @param mixed $baseUri
26
     *
27
     * @return string
28
     */
29 2
    public function get($uri = null, $args = null, bool $local = null, $baseUri = null): string
30
    {
31 2
        return self::getAbsolutePath(parent::get($uri, $args, $local, $baseUri));
32
    }
33
    
34
    /**
35
     * @param string $path
36
     *
37
     * @return string
38
     */
39 2
    public static function getAbsolutePath(string $path): string
40
    {
41 2
        if (strpos($path, 'https://') === 0) {
42 2
            return $path;
43
        }
44 2
        if (strpos($path, 'http://') === 0) {
45 2
            return $path;
46
        }
47 2
        if (strpos($path, '//') === 0) {
48 2
            return $path;
49
        }
50
        
51 2
        $path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path);
52 2
        $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'mb_strlen');
53 2
        $absolutes = [];
54 2
        foreach ($parts as $part) {
55 2
            if ('.' === $part) {
56 2
                continue;
57
            }
58 2
            if ('..' === $part) {
59 2
                array_pop($absolutes);
60
            }
61
            else {
62 2
                $absolutes[] = $part;
63
            }
64
        }
65 2
        return '/' . implode(DIRECTORY_SEPARATOR, $absolutes);
66
    }
67
}
68