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

JsonPointerAware::toJsonPointer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 2
rs 10
c 2
b 0
f 0
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