5
5
namespace TypeLang \PHPDoc \Parser \Tag ;
6
6
7
7
use TypeLang \PHPDoc \Exception \InvalidTagNameException ;
8
+ use TypeLang \PHPDoc \FactoryInterface ;
8
9
use TypeLang \PHPDoc \Parser \Description \DescriptionParserInterface ;
9
10
use TypeLang \PHPDoc \Tag \Tag ;
10
11
@@ -15,6 +16,10 @@ final class TagParser implements TagParserInterface
15
16
*/
16
17
private const PATTERN_TAG = '\G@[a-zA-Z_\x80-\xff \\\][\w\x80-\xff\-: \\\]* ' ;
17
18
19
+ public function __construct (
20
+ private readonly FactoryInterface $ tags ,
21
+ ) {}
22
+
18
23
/**
19
24
* Read tag name from passed content.
20
25
*
@@ -54,33 +59,17 @@ private function getTagName(string $content): string
54
59
}
55
60
56
61
/**
57
- * @return array{non-empty-string, string}
58
62
* @throws InvalidTagNameException
59
63
*/
60
- private function getTagParts (string $ content ): array
64
+ public function parse (string $ tag , DescriptionParserInterface $ parser ): Tag
61
65
{
62
- $ name = $ this ->getTagName ($ content );
66
+ $ name = $ this ->getTagName ($ tag );
63
67
/** @var non-empty-string $name */
64
68
$ name = \substr ($ name , 1 );
65
69
66
- $ content = \substr ($ content , \strlen ($ name ) + 1 );
70
+ $ content = \substr ($ tag , \strlen ($ name ) + 1 );
67
71
$ content = \ltrim ($ content );
68
72
69
- return [$ name , $ content ];
70
- }
71
-
72
- /**
73
- * @throws InvalidTagNameException
74
- */
75
- public function parse (string $ tag , DescriptionParserInterface $ parser = null ): Tag
76
- {
77
- // Tag name like ["var", "example"] extracted from "@var example"
78
- [$ name , $ content ] = $ this ->getTagParts ($ tag );
79
-
80
- if ($ parser !== null ) {
81
- $ content = $ parser ->parse ($ content , $ this );
82
- }
83
-
84
- return new Tag ($ name , $ content );
73
+ return $ this ->tags ->create ($ name , $ content , $ parser );
85
74
}
86
75
}
0 commit comments