Completed
Push — master ( c16c79...ab8250 )
by Edward
04:36
created

ExistingValueResult::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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