Completed
Push — master ( 7dba56...6875ae )
by Oscar
10:21
created

Path   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fix() 0 11 2
A join() 0 4 1
1
<?php
2
3
namespace Psr7Middlewares\Utils;
4
5
/**
6
 * Common functions to work with paths.
7
 */
8
class Path
9
{
10
    /**
11
     * helper function to fix paths '//' or '/./' or '/foo/../' in a path.
12
     *
13
     * @param string $path Path to resolve
14
     *
15
     * @return string
16
     */
17
    public static function fix($path)
18
    {
19
        $path = str_replace('\\', '/', $path); //windows paths
20
        $replace = ['#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'];
21
22
        do {
23
            $path = preg_replace($replace, '/', $path, -1, $n);
24
        } while ($n > 0);
25
26
        return $path;
27
    }
28
29
    /**
30
     * Join several pieces into a path.
31
     * 
32
     * @param string $piece1
0 ignored issues
show
Bug introduced by
There is no parameter named $piece1. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
33
     * @param string $piece2
0 ignored issues
show
Bug introduced by
There is no parameter named $piece2. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
34
     *                       ...
35
     * 
36
     * @return string
37
     */
38
    public static function join()
39
    {
40
        return self::fix(implode('/', func_get_args()));
41
    }
42
}
43