Parser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Remorhaz\JSON\Pointer\Parser;
6
7
use Remorhaz\JSON\Pointer\Locator\LocatorBuilder;
8
use Remorhaz\JSON\Pointer\Locator\LocatorInterface;
9
use Remorhaz\JSON\Pointer\Locator\ReferenceFactory;
10
use Remorhaz\JSON\Pointer\Locator\ReferenceFactoryInterface;
11
use Remorhaz\UniLex\Exception as UniLexException;
12
13
final class Parser implements ParserInterface
14
{
15
16
    private $ll1ParserFactory;
17
18
    private $referenceFactory;
19
20 1
    public static function create(): ParserInterface
21
    {
22 1
        return new self(
23 1
            new Ll1ParserFactory(),
24 1
            new ReferenceFactory()
25
        );
26
    }
27
28 5
    public function __construct(
29
        Ll1ParserFactoryInterface $ll1ParserFactory,
30
        ReferenceFactoryInterface $referenceFactory
31
    ) {
32 5
        $this->ll1ParserFactory = $ll1ParserFactory;
33 5
        $this->referenceFactory = $referenceFactory;
34 5
    }
35
36
    /**
37
     * @param string $pointer
38
     * @return LocatorInterface
39
     * @throws UniLexException
40
     */
41 4
    public function buildLocator(string $pointer): LocatorInterface
42
    {
43 4
        $locatorBuilder = new LocatorBuilder($this->referenceFactory);
44
        $this
45 4
            ->ll1ParserFactory
46 4
            ->createParser($pointer, $locatorBuilder)
47 4
            ->run();
48
49 4
        return $locatorBuilder->getLocator();
50
    }
51
}
52