Passed
Push — master ( 515bb9...e7e904 )
by Andrea Marco
03:05 queued 14s
created

Dot   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toPointer() 0 6 2
A __construct() 0 1 1
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