SelectResult::encode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
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
use function array_map;
12
13
final class SelectResult implements SelectResultInterface
14
{
15
16
    private $encoder;
17
18
    private $decoder;
19
20
    private $values;
21
22 7
    public function __construct(
23
        ValueEncoderInterface $encoder,
24
        ValueDecoderInterface $decoder,
25
        ValueInterface ...$values
26
    ) {
27 7
        $this->encoder = $encoder;
28 7
        $this->decoder = $decoder;
29 7
        $this->values = $values;
30 7
    }
31
32
    /**
33
     * {@inheritDoc}
34
     *
35
     * @return array
36
     */
37 2
    public function decode(): array
38
    {
39 2
        return array_map([$this->decoder, 'exportValue'], $this->values);
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     *
45
     * @return string[]
46
     */
47 3
    public function encode(): array
48
    {
49 3
        return array_map([$this->encoder, 'exportValue'], $this->values);
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     *
55
     * @return ValueInterface[]
56
     */
57 2
    public function get(): array
58
    {
59 2
        return $this->values;
60
    }
61
}
62