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

SelectResult   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 37
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 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\ValueDecoderInterface;
8
use Remorhaz\JSON\Data\Export\ValueEncoderInterface;
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 5
    public function __construct(
21
        ValueEncoderInterface $encoder,
22
        ValueDecoderInterface $decoder,
23
        ValueInterface ...$values
24
    ) {
25 5
        $this->encoder = $encoder;
26 5
        $this->decoder = $decoder;
27 5
        $this->values = $values;
28 5
    }
29
30
    /**
31
     * {@inheritDoc}
32
     *
33
     * @return array
34
     */
35 2
    public function decode(): array
36
    {
37 2
        return array_map([$this->decoder, 'exportValue'], $this->values);
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     *
43
     * @return string[]
44
     */
45 3
    public function encode(): array
46
    {
47 3
        return array_map([$this->encoder, 'exportValue'], $this->values);
48
    }
49
}
50