1717use phpDocumentor \Reflection \DocBlock \Tags \Author ;
1818use phpDocumentor \Reflection \DocBlock \Tags \Covers ;
1919use phpDocumentor \Reflection \DocBlock \Tags \Deprecated ;
20+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \AbstractPHPStanFactory ;
21+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \ExtendsFactory ;
2022use phpDocumentor \Reflection \DocBlock \Tags \Factory \Factory ;
23+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \ImplementsFactory ;
24+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \MethodFactory ;
25+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \ParamFactory ;
26+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \PropertyFactory ;
27+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \PropertyReadFactory ;
28+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \PropertyWriteFactory ;
29+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \ReturnFactory ;
30+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \TemplateExtendsFactory ;
31+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \TemplateFactory ;
32+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \TemplateImplementsFactory ;
33+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \ThrowsFactory ;
34+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \VarFactory ;
2135use phpDocumentor \Reflection \DocBlock \Tags \Generic ;
2236use phpDocumentor \Reflection \DocBlock \Tags \InvalidTag ;
2337use phpDocumentor \Reflection \DocBlock \Tags \Link as LinkTag ;
2438use phpDocumentor \Reflection \DocBlock \Tags \Method ;
25- use phpDocumentor \Reflection \DocBlock \Tags \Mixin ;
26- use phpDocumentor \Reflection \DocBlock \Tags \Param ;
27- use phpDocumentor \Reflection \DocBlock \Tags \Property ;
28- use phpDocumentor \Reflection \DocBlock \Tags \PropertyRead ;
29- use phpDocumentor \Reflection \DocBlock \Tags \PropertyWrite ;
30- use phpDocumentor \Reflection \DocBlock \Tags \Return_ ;
3139use phpDocumentor \Reflection \DocBlock \Tags \See as SeeTag ;
3240use phpDocumentor \Reflection \DocBlock \Tags \Since ;
3341use phpDocumentor \Reflection \DocBlock \Tags \Source ;
3442use phpDocumentor \Reflection \DocBlock \Tags \TemplateCovariant ;
3543use phpDocumentor \Reflection \DocBlock \Tags \Throws ;
3644use phpDocumentor \Reflection \DocBlock \Tags \Uses ;
37- use phpDocumentor \Reflection \DocBlock \Tags \Var_ ;
3845use phpDocumentor \Reflection \DocBlock \Tags \Version ;
3946use phpDocumentor \Reflection \FqsenResolver ;
47+ use phpDocumentor \Reflection \TypeResolver ;
4048use phpDocumentor \Reflection \Types \Context as TypeContext ;
4149use ReflectionMethod ;
4250use ReflectionNamedType ;
@@ -77,7 +85,7 @@ final class StandardTagFactory implements TagFactory
7785 public const REGEX_TAGNAME = '[\w\-\_ \\\\:]+ ' ;
7886
7987 /**
80- * @var array<class-string<Tag>|Factory> An array with a tag as a key, and an
88+ * @var array<string, class-string<Tag>|Tag |Factory> An array with a tag as a key, and an
8189 * FQCN to a class that handles it as an array value.
8290 */
8391 private array $ tagHandlerMappings = [
@@ -86,21 +94,13 @@ final class StandardTagFactory implements TagFactory
8694 'deprecated ' => Deprecated::class,
8795 // 'example' => '\phpDocumentor\Reflection\DocBlock\Tags\Example',
8896 'link ' => LinkTag::class,
89- 'mixin ' => Mixin::class,
9097 'method ' => Method::class,
91- 'param ' => Param::class,
92- 'property-read ' => PropertyRead::class,
93- 'property ' => Property::class,
94- 'property-write ' => PropertyWrite::class,
95- 'return ' => Return_::class,
9698 'see ' => SeeTag::class,
9799 'since ' => Since::class,
98100 'source ' => Source::class,
99101 'template-covariant ' => TemplateCovariant::class,
100102 'throw ' => Throws::class,
101- 'throws ' => Throws::class,
102103 'uses ' => Uses::class,
103- 'var ' => Var_::class,
104104 'version ' => Version::class,
105105 ];
106106
@@ -124,24 +124,58 @@ final class StandardTagFactory implements TagFactory
124124 */
125125 private array $ serviceLocator = [];
126126
127+ private function __construct (FqsenResolver $ fqsenResolver )
128+ {
129+ $ this ->fqsenResolver = $ fqsenResolver ;
130+
131+ $ this ->addService ($ fqsenResolver , FqsenResolver::class);
132+ }
133+
127134 /**
128- * Initialize this tag factory with the means to resolve an FQSEN and optionally a list of tag handlers.
129- *
130- * If no tag handlers are provided than the default list in the {@see self::$tagHandlerMappings} property
131- * is used.
135+ * Initialize this tag factory with the means to resolve an FQSEN.
132136 *
133137 * @see self::registerTagHandler() to add a new tag handler to the existing default list.
134- *
135- * @param array<class-string<Tag>> $tagHandlers
136138 */
137- public function __construct (FqsenResolver $ fqsenResolver, ? array $ tagHandlers = null )
139+ public static function createInstance (FqsenResolver $ fqsenResolver): self
138140 {
139- $ this ->fqsenResolver = $ fqsenResolver ;
140- if ($ tagHandlers !== null ) {
141- $ this ->tagHandlerMappings = $ tagHandlers ;
142- }
141+ $ tagFactory = new self ($ fqsenResolver );
142+ $ descriptionFactory = new DescriptionFactory ($ tagFactory );
143+
144+ $ typeResolver = new TypeResolver ($ fqsenResolver );
145+
146+ $ phpstanTagFactory = new AbstractPHPStanFactory (
147+ new ParamFactory ($ typeResolver , $ descriptionFactory ),
148+ new VarFactory ($ typeResolver , $ descriptionFactory ),
149+ new ReturnFactory ($ typeResolver , $ descriptionFactory ),
150+ new PropertyFactory ($ typeResolver , $ descriptionFactory ),
151+ new PropertyReadFactory ($ typeResolver , $ descriptionFactory ),
152+ new PropertyWriteFactory ($ typeResolver , $ descriptionFactory ),
153+ new MethodFactory ($ typeResolver , $ descriptionFactory ),
154+ new ImplementsFactory ($ typeResolver , $ descriptionFactory ),
155+ new ExtendsFactory ($ typeResolver , $ descriptionFactory ),
156+ new TemplateFactory ($ typeResolver , $ descriptionFactory ),
157+ new TemplateImplementsFactory ($ typeResolver , $ descriptionFactory ),
158+ new TemplateExtendsFactory ($ typeResolver , $ descriptionFactory ),
159+ new ThrowsFactory ($ typeResolver , $ descriptionFactory ),
160+ );
143161
144- $ this ->addService ($ fqsenResolver , FqsenResolver::class);
162+ $ tagFactory ->addService ($ descriptionFactory );
163+ $ tagFactory ->addService ($ typeResolver );
164+ $ tagFactory ->registerTagHandler ('param ' , $ phpstanTagFactory );
165+ $ tagFactory ->registerTagHandler ('var ' , $ phpstanTagFactory );
166+ $ tagFactory ->registerTagHandler ('return ' , $ phpstanTagFactory );
167+ $ tagFactory ->registerTagHandler ('property ' , $ phpstanTagFactory );
168+ $ tagFactory ->registerTagHandler ('property-read ' , $ phpstanTagFactory );
169+ $ tagFactory ->registerTagHandler ('property-write ' , $ phpstanTagFactory );
170+ $ tagFactory ->registerTagHandler ('method ' , $ phpstanTagFactory );
171+ $ tagFactory ->registerTagHandler ('extends ' , $ phpstanTagFactory );
172+ $ tagFactory ->registerTagHandler ('implements ' , $ phpstanTagFactory );
173+ $ tagFactory ->registerTagHandler ('template ' , $ phpstanTagFactory );
174+ $ tagFactory ->registerTagHandler ('template-extends ' , $ phpstanTagFactory );
175+ $ tagFactory ->registerTagHandler ('template-implements ' , $ phpstanTagFactory );
176+ $ tagFactory ->registerTagHandler ('throws ' , $ phpstanTagFactory );
177+
178+ return $ tagFactory ;
145179 }
146180
147181 public function create (string $ tagLine , ?TypeContext $ context = null ): Tag
@@ -238,7 +272,7 @@ private function createTag(string $body, string $name, TypeContext $context): Ta
238272 /**
239273 * Determines the Fully Qualified Class Name of the Factory or Tag (containing a Factory Method `create`).
240274 *
241- * @return class-string<Tag>|Factory
275+ * @return class-string<Tag>|Tag| Factory
242276 */
243277 private function findHandlerClassName (string $ tagName , TypeContext $ context )
244278 {
@@ -302,7 +336,7 @@ private function getArgumentsForParametersFromWiring(array $parameters, array $l
302336 * Retrieves a series of ReflectionParameter objects for the static 'create' method of the given
303337 * tag handler class name.
304338 *
305- * @param class-string|Factory $handler
339+ * @param class-string<Tag>|Tag |Factory $handler
306340 *
307341 * @return ReflectionParameter[]
308342 */
0 commit comments