Passed
Push — master ( ec8827...deea55 )
by Edward
02:26
created

QueryFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A createQuery() 0 3 1
A create() 0 12 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Remorhaz\JSON\Patch\Query;
5
6
use Collator;
7
use Remorhaz\JSON\Data\Comparator\EqualValueComparator;
8
use Remorhaz\JSON\Data\Export\ValueDecoder;
9
use Remorhaz\JSON\Data\Export\ValueDecoderInterface;
10
use Remorhaz\JSON\Data\Export\ValueEncoder;
11
use Remorhaz\JSON\Data\Export\ValueEncoderInterface;
12
use Remorhaz\JSON\Data\Value\NodeValueInterface;
13
use Remorhaz\JSON\Patch\Operation\OperationFactory;
14
use Remorhaz\JSON\Patch\Operation\OperationFactoryInterface;
15
use Remorhaz\JSON\Pointer\Processor\Processor as PointerProcessor;
16
use Remorhaz\JSON\Pointer\Query\QueryFactory as PointerQueryFactory;
17
18
final class QueryFactory implements QueryFactoryInterface
19
{
20
21
    private $operationFactory;
22
23
    private $encoder;
24
25
    private $decoder;
26
27
    public static function create(): QueryFactoryInterface
28
    {
29
        $decoder = new ValueDecoder;
30
31
        return new self(
32
            new OperationFactory(
33
                PointerQueryFactory::create(),
34
                PointerProcessor::create(),
35
                new EqualValueComparator(new Collator('UTF-8'))
36
            ),
37
            new ValueEncoder($decoder),
38
            $decoder
39
        );
40
    }
41
42
    public function __construct(
43
        OperationFactoryInterface $operationFactory,
44
        ValueEncoderInterface $encoder,
45
        ValueDecoderInterface $decoder
46
    ) {
47
        $this->operationFactory = $operationFactory;
48
        $this->encoder = $encoder;
49
        $this->decoder = $decoder;
50
    }
51
52
    public function createQuery(NodeValueInterface $patch): QueryInterface
53
    {
54
        return new LazyQuery($this->operationFactory, $this->encoder, $this->decoder, $patch);
55
    }
56
}
57