Failed Conditions
Push — type ( 257e93...5997a7 )
by Michael
02:15
created

NativeTypeParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 8
dl 0
loc 27
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parsePropertyType() 0 8 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\TypeParser;
6
7
use Doctrine\Annotations\Type\Type;
8
use Hoa\Compiler\Llk\Llk;
9
use Hoa\Compiler\Llk\Parser;
10
use Hoa\Compiler\Llk\TreeNode;
11
use Hoa\File\Read;
12
use function preg_match;
13
14
/**
15
 * @internal
16
 */
17
final class NativeTypeParser implements TypeParser
18
{
19
    private const ROOT_RULE = 'type';
20
21
    /** @var Parser */
22
    private $compiler;
23
24
    /** @var TypeVisitor */
25
    private $visitor;
26
27
    public function __construct()
28
    {
29
        $this->compiler = Llk::load(new Read(__DIR__ . '/type.pp'));
30
        $this->visitor  = new TypeVisitor();
31
    }
32
33
    /**
34
     * @param array<string, string> $imports
35
     */
36
    public function parsePropertyType(string $docBlock, array $imports) : Type
37
    {
38
        preg_match('~@var\s+(.+)$~', $docBlock, $match);
39
40
        /** @var TreeNode $trace */
41
        $tree = $this->compiler->parse($match[1], self::ROOT_RULE);
42
43
        return $this->visitor->visit($tree);
44
    }
45
}
46