|
22 | 22 | /** |
23 | 23 | * @psalm-suppress UndefinedAttributeClass : JetBrains language attribute may not be available |
24 | 24 | */ |
25 | | -class DocBlockFactory implements DocBlockFactoryInterface |
| 25 | +class Parser implements ParserInterface |
26 | 26 | { |
27 | | - private readonly CommentParserInterface $comment; |
28 | | - |
29 | | - private readonly DescriptionParserInterface $description; |
30 | | - |
31 | | - private readonly TagParserInterface $tags; |
32 | | - |
33 | | - public function __construct() |
34 | | - { |
35 | | - $this->comment = new LexerAwareCommentParser(); |
36 | | - $this->description = new SprintfDescriptionReader(); |
37 | | - $this->tags = new TagParser(); |
38 | | - } |
| 27 | + public function __construct( |
| 28 | + private readonly CommentParserInterface $comments = new LexerAwareCommentParser(), |
| 29 | + private readonly DescriptionParserInterface $descriptions = new SprintfDescriptionReader(), |
| 30 | + private readonly TagParserInterface $tags = new TagParser(), |
| 31 | + ) {} |
39 | 32 |
|
40 | 33 | /** |
41 | 34 | * @throws RuntimeExceptionInterface |
42 | 35 | */ |
43 | | - public function create(#[Language('PHP')] string $docblock): DocBlock |
| 36 | + public function parse(#[Language('PHP')] string $docblock): DocBlock |
44 | 37 | { |
45 | 38 | $mapper = new SourceMap(); |
46 | 39 |
|
@@ -88,9 +81,9 @@ private function analyze(string $docblock): \Generator |
88 | 81 | foreach ($blocks->getReturn() as $block) { |
89 | 82 | try { |
90 | 83 | if ($description === null) { |
91 | | - $description = $this->description->parse($block, $this->tags); |
| 84 | + $description = $this->descriptions->parse($block, $this->tags); |
92 | 85 | } else { |
93 | | - $tags[] = $this->tags->parse($block, $this->description); |
| 86 | + $tags[] = $this->tags->parse($block, $this->descriptions); |
94 | 87 | } |
95 | 88 | } catch (RuntimeExceptionInterface $e) { |
96 | 89 | throw $e->withSource( |
@@ -123,7 +116,7 @@ private function groupByCommentSections(string $docblock): \Generator |
123 | 116 | $current = ''; |
124 | 117 | $blocks = []; |
125 | 118 |
|
126 | | - foreach ($this->comment->parse($docblock) as $segment) { |
| 119 | + foreach ($this->comments->parse($docblock) as $segment) { |
127 | 120 | yield $segment; |
128 | 121 |
|
129 | 122 | if (\str_starts_with($segment->text, '@')) { |
|
0 commit comments