ExistingResult::encode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Pointer\Processor\Result;
6
7
use Remorhaz\JSON\Data\Export\ValueDecoderInterface;
8
use Remorhaz\JSON\Data\Export\ValueEncoderInterface;
9
use Remorhaz\JSON\Data\Value\NodeValueInterface;
10
11
final class ExistingResult implements ResultInterface
12
{
13
14
    private $encoder;
15
16
    private $decoder;
17
18
    private $nodeValue;
19
20 6
    public function __construct(
21
        ValueEncoderInterface $encoder,
22
        ValueDecoderInterface $decoder,
23
        NodeValueInterface $nodeValue
24
    ) {
25 6
        $this->encoder = $encoder;
26 6
        $this->decoder = $decoder;
27 6
        $this->nodeValue = $nodeValue;
28 6
    }
29
30 1
    public function exists(): bool
31
    {
32 1
        return true;
33
    }
34
35 2
    public function encode(): string
36
    {
37
        return $this
38 2
            ->encoder
39 2
            ->exportValue($this->nodeValue);
40
    }
41
42 2
    public function decode()
43
    {
44
        return $this
45 2
            ->decoder
46 2
            ->exportValue($this->nodeValue);
47
    }
48
49 1
    public function get(): NodeValueInterface
50
    {
51 1
        return $this->nodeValue;
52
    }
53
}
54