Passed
Push — master ( 3a32e2...77143f )
by Edward
04:21
created

Parser::__construct()   A

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