Passed
Push — master ( 162b02...da0f52 )
by Edward
02:27
created

SelectResult   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toJson() 0 3 1
A __construct() 0 5 1
A encode() 0 3 1
A decode() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Path\Processor\Result;
5
6
use function array_map;
7
use Remorhaz\JSON\Data\Export\DecoderInterface;
8
use Remorhaz\JSON\Data\Export\EncoderInterface;
9
use Remorhaz\JSON\Data\Value\ValueInterface;
10
11
final class SelectResult implements SelectResultInterface
12
{
13
14
    private $encoder;
15
16
    private $decoder;
17
18
    private $values;
19
20
    public function __construct(EncoderInterface $encoder, DecoderInterface $decoder, ValueInterface ...$values)
21
    {
22
        $this->encoder = $encoder;
23
        $this->decoder = $decoder;
24
        $this->values = $values;
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     *
30
     * @return array
31
     */
32
    public function decode(): array
33
    {
34
        return array_map([$this->decoder, 'exportValue'], $this->values);
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     *
40
     * @return string[]
41
     */
42
    public function encode(): array
43
    {
44
        return array_map([$this->encoder, 'exportValue'], $this->values);
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     *
50
     * @return string[]
51
     * @deprecated
52
     */
53
    public function toJson(): array
54
    {
55
        return $this->encode();
56
    }
57
}
58