Passed
Push — master ( c6e62a...162b02 )
by Edward
03:02
created

ExistingSelectOneResult   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 33
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 5 1
A __construct() 0 5 1
A exists() 0 3 1
A encode() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Processor;
5
6
use Remorhaz\JSON\Data\Export\DecoderInterface;
7
use Remorhaz\JSON\Data\Export\EncoderInterface;
8
use Remorhaz\JSON\Data\Value\ValueInterface;
9
10
final class ExistingSelectOneResult implements SelectOneResultInterface
11
{
12
13
    private $jsonEncoder;
14
15
    private $jsonDecoder;
16
17
    private $value;
18
19
    public function __construct(EncoderInterface $jsonEncoder, DecoderInterface $jsonDecoder, ValueInterface $value)
20
    {
21
        $this->jsonEncoder = $jsonEncoder;
22
        $this->jsonDecoder = $jsonDecoder;
23
        $this->value = $value;
24
    }
25
26
    public function exists(): bool
27
    {
28
        return true;
29
    }
30
31
    public function encode(): string
32
    {
33
        return $this
34
            ->jsonEncoder
35
            ->exportValue($this->value);
36
    }
37
38
    public function decode()
39
    {
40
        return $this
41
            ->jsonDecoder
42
            ->exportValue($this->value);
43
    }
44
}
45