Passed
Pull Request — master (#24)
by Viacheslav
03:13
created

PointerUtil   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDataPointer() 0 11 3
1
<?php
2
3
namespace Swaggest\JsonSchema\Path;
4
5
use Swaggest\JsonDiff\JsonPointer;
6
7
class PointerUtil
8
{
9
    /**
10
     * Builds JSON pointer to data from processing path
11
     * Path example: #->properties:responses->additionalProperties:envvar->properties:schema
12
     * @param string $path
13
     * @return string
14
     * @todo proper path items escaping/moving to native JSON pointers
15
     */
16 2
    public static function getDataPointer($path) {
17 2
        $items = explode('->', $path);
18 2
        unset($items[0]);
19 2
        $result = '#';
20 2
        foreach ($items as $item) {
21 1
            $parts = explode(':', $item);
22 1
            if (isset($parts[1])) {
23 1
                $result .= '/' . JsonPointer::escapeSegment($parts[1], true);
24
            }
25
        }
26 2
        return $result;
27
    }
28
29
}