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

Parser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A buildLocator() 0 9 1
A create() 0 5 1
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