Path   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 21
c 2
b 0
f 0
dl 0
loc 36
ccs 21
cts 21
cp 1
rs 10
wmc 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A quoteUrldecode() 0 9 3
B fitsPattern() 0 23 7
1
<?php
2
3
namespace Swaggest\ApiCompat;
4
5
6
use Swaggest\JsonDiff\JsonPointer;
7
8
class Path
9
{
10 2
    public static function fitsPattern($path, $pattern)
11
    {
12 2
        $path = explode('/', $path);
13 2
        $pattern = explode('/', $pattern);
14
15 2
        foreach ($path as $i => $item) {
16 2
            if (!isset($pattern[$i])) {
17 2
                return false;
18
            }
19 2
            $pitem = $pattern[$i];
20 2
            if ($pitem === '...') {
21 2
                return true;
22
            }
23 2
            if (($pitem === '*') || $pitem === $item) {
24 2
                continue;
25
            } else {
26 2
                return false;
27
            }
28
        }
29 2
        if (count($pattern) > count($path)) {
30 2
            return false;
31
        }
32 2
        return true;
33
    }
34
35 1
    public static function quoteUrldecode($path)
36
    {
37 1
        $path = JsonPointer::splitPath($path);
38 1
        foreach ($path as &$item) {
39 1
            if ($item !== $u = urlencode($item)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $u is dead and can be removed.
Loading history...
40 1
                $item = "'" . $item . "'";
41
            }
42
        }
43 1
        return '#/' . implode('/', $path);
44
    }
45
}