QueryFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
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 2
    public static function create(): QueryFactoryInterface
28
    {
29 2
        $decoder = new ValueDecoder;
30
31 2
        return new self(
32 2
            new OperationFactory(
33 2
                PointerQueryFactory::create(),
34 2
                PointerProcessor::create(),
35 2
                new EqualValueComparator(new Collator('UTF-8'))
36
            ),
37 2
            new ValueEncoder($decoder),
38
            $decoder
39
        );
40
    }
41
42 5
    public function __construct(
43
        OperationFactoryInterface $operationFactory,
44
        ValueEncoderInterface $encoder,
45
        ValueDecoderInterface $decoder
46
    ) {
47 5
        $this->operationFactory = $operationFactory;
48 5
        $this->encoder = $encoder;
49 5
        $this->decoder = $decoder;
50 5
    }
51
52 4
    public function createQuery(NodeValueInterface $patch): QueryInterface
53
    {
54 4
        return new LazyQuery($this->operationFactory, $this->encoder, $this->decoder, $patch);
55
    }
56
}
57