ExistingValueResult::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Path\Processor\Result;
6
7
use Remorhaz\JSON\Data\Export\ValueDecoderInterface;
8
use Remorhaz\JSON\Data\Export\ValueEncoderInterface;
9
use Remorhaz\JSON\Data\Value\ValueInterface;
10
11
final class ExistingValueResult implements ValueResultInterface
12
{
13
14
    private $jsonEncoder;
15
16
    private $jsonDecoder;
17
18
    private $value;
19
20 6
    public function __construct(
21
        ValueEncoderInterface $jsonEncoder,
22
        ValueDecoderInterface $jsonDecoder,
23
        ValueInterface $value
24
    ) {
25 6
        $this->jsonEncoder = $jsonEncoder;
26 6
        $this->jsonDecoder = $jsonDecoder;
27 6
        $this->value = $value;
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
            ->jsonEncoder
39 2
            ->exportValue($this->value);
40
    }
41
42 2
    public function decode()
43
    {
44
        return $this
45 2
            ->jsonDecoder
46 2
            ->exportValue($this->value);
47
    }
48
49 1
    public function get(): ValueInterface
50
    {
51 1
        return $this->value;
52
    }
53
}
54