Passed
Push — master ( 222a88...547f19 )
by Andrea Marco
02:49 queued 12s
created

JsonPointerAware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A toJsonPointer() 0 9 2
1
<?php
2
3
namespace Cerbero\LazyJson\Concerns;
4
5
/**
6
 * The JSON pointer aware trait.
7
 *
8
 */
9
trait JsonPointerAware
10
{
11
    /**
12
     * Retrieve a JSON pointer from the given dot-noted path.
13
     *
14
     * @param string $path
15
     * @return string
16
     */
17 10
    protected function toJsonPointer(string $path): string
18
    {
19 10
        if (empty($path = trim($path))) {
20 9
            return '';
21
        }
22
23
        // @todo replace * with - after https://github.com/halaxa/json-machine/pull/47 is merged:
24
        // return '/' . str_replace(['~', '/', '.', '*'], ['~0', '~1', '/', '-'], $path);
25 1
        return '/' . str_replace(['~', '/', '.'], ['~0', '~1', '/'], $path);
26
    }
27
}
28