Passed
Push — master ( 8e4f12...3d58fd )
by Edward
05:59
created

ExistingValueResult   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A encode() 0 5 1
A decode() 0 5 1
A __construct() 0 8 1
A exists() 0 3 1
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 5
    public function __construct(
20
        ValueEncoderInterface $jsonEncoder,
21
        ValueDecoderInterface $jsonDecoder,
22
        ValueInterface $value
23
    ) {
24 5
        $this->jsonEncoder = $jsonEncoder;
25 5
        $this->jsonDecoder = $jsonDecoder;
26 5
        $this->value = $value;
27 5
    }
28
29 1
    public function exists(): bool
30
    {
31 1
        return true;
32
    }
33
34 2
    public function encode(): string
35
    {
36
        return $this
37 2
            ->jsonEncoder
38 2
            ->exportValue($this->value);
39
    }
40
41 2
    public function decode()
42
    {
43
        return $this
44 2
            ->jsonDecoder
45 2
            ->exportValue($this->value);
46
    }
47
}
48