-
-
Notifications
You must be signed in to change notification settings - Fork 156
Expand file tree
/
Copy pathDocblockParser.php
More file actions
33 lines (27 loc) · 731 Bytes
/
Copy pathDocblockParser.php
File metadata and controls
33 lines (27 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace Phpactor\DocblockParser;
use Phpactor\DocblockParser\Ast\Docblock;
use RuntimeException;
final class DocblockParser
{
public function __construct(
private Lexer $lexer,
private Parser $parser
) {
}
public static function create(): self
{
return new self(new Lexer(), new Parser());
}
public function parse(string $docblock): Docblock
{
$node = $this->parser->parse($this->lexer->lex($docblock));
if (!$node instanceof Docblock) {
throw new RuntimeException(sprintf(
'Expected a Docblock node from parser, but got "%s"',
get_class($node)
));
}
return $node;
}
}