Dot::toPointer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LazyJsonPages\Data;
6
7
/**
8
 * The dot value object.
9
 */
10
final class Dot
11
{
12
    /**
13
     * Instantiate the class.
14
     */
15 50
    public function __construct(public readonly string $dot) {}
16
17
    /**
18
     * Retrieve the JSON pointer of this dot.
19
     */
20 50
    public function toPointer(): string
21
    {
22 50
        $search = ['~', '/', '.', '*', '\\', '"'];
23 50
        $replace = ['~0', '~1', '/', '-', '\\\\', '\"'];
24
25 50
        return $this->dot == '*' ? '' : '/' . str_replace($search, $replace, $this->dot);
26
    }
27
}
28