8
8
use phpDocumentor \Reflection \DocBlock \DescriptionFactory ;
9
9
use phpDocumentor \Reflection \DocBlock \Serializer as DocBlockSerializer ;
10
10
use phpDocumentor \Reflection \DocBlock \StandardTagFactory ;
11
+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \AbstractPHPStanFactory ;
12
+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \MethodFactory ;
13
+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \ParamFactory ;
14
+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \PropertyFactory ;
15
+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \PropertyReadFactory ;
16
+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \PropertyWriteFactory ;
17
+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \ReturnFactory ;
18
+ use phpDocumentor \Reflection \DocBlock \Tags \Factory \VarFactory ;
11
19
use phpDocumentor \Reflection \DocBlockFactory ;
12
20
use phpDocumentor \Reflection \FqsenResolver ;
13
21
use phpDocumentor \Reflection \TypeResolver ;
@@ -340,13 +348,41 @@ protected function createPhpDocs()
340
348
$ context = (new ContextFactory ())->createFromReflector ($ this ->reflection );
341
349
$ summary = "Class {$ this ->class }" ;
342
350
351
+ $ fqsenResolver = new FqsenResolver ();
352
+ $ tagFactory = new StandardTagFactory ($ fqsenResolver );
353
+ $ descriptionFactory = new DescriptionFactory ($ tagFactory );
354
+ $ typeResolver = new TypeResolver ($ fqsenResolver );
355
+
356
+ $ phpstanTagFactory = new AbstractPHPStanFactory (
357
+ new ParamFactory ($ typeResolver , $ descriptionFactory ),
358
+ new VarFactory ($ typeResolver , $ descriptionFactory ),
359
+ new ReturnFactory ($ typeResolver , $ descriptionFactory ),
360
+ new PropertyFactory ($ typeResolver , $ descriptionFactory ),
361
+ new PropertyReadFactory ($ typeResolver , $ descriptionFactory ),
362
+ new PropertyWriteFactory ($ typeResolver , $ descriptionFactory ),
363
+ new MethodFactory ($ typeResolver , $ descriptionFactory )
364
+ );
365
+
366
+ $ tagFactory ->addService ($ descriptionFactory );
367
+ $ tagFactory ->addService ($ typeResolver );
368
+
369
+ $ tagFactory ->registerTagHandler ('param ' , $ phpstanTagFactory );
370
+ $ tagFactory ->registerTagHandler ('var ' , $ phpstanTagFactory );
371
+ $ tagFactory ->registerTagHandler ('return ' , $ phpstanTagFactory );
372
+ $ tagFactory ->registerTagHandler ('property ' , $ phpstanTagFactory );
373
+ $ tagFactory ->registerTagHandler ('property-read ' , $ phpstanTagFactory );
374
+ $ tagFactory ->registerTagHandler ('property-write ' , $ phpstanTagFactory );
375
+ $ tagFactory ->registerTagHandler ('method ' , $ phpstanTagFactory );
376
+
377
+ $ blockFactory = new DocBlockFactory ($ descriptionFactory , $ tagFactory );
378
+
343
379
$ properties = [];
344
380
$ methods = [];
345
381
$ tags = [];
346
382
347
383
try {
348
384
//读取文件注释
349
- $ phpdoc = DocBlockFactory:: createInstance () ->create ($ this ->reflection , $ context );
385
+ $ phpdoc = $ blockFactory ->create ($ this ->reflection , $ context );
350
386
351
387
$ summary = $ phpdoc ->getSummary ();
352
388
$ properties = [];
@@ -373,13 +409,6 @@ protected function createPhpDocs()
373
409
374
410
}
375
411
376
- $ fqsenResolver = new FqsenResolver ();
377
- $ tagFactory = new StandardTagFactory ($ fqsenResolver );
378
- $ descriptionFactory = new DescriptionFactory ($ tagFactory );
379
-
380
- $ tagFactory ->addService ($ descriptionFactory );
381
- $ tagFactory ->addService (new TypeResolver ($ fqsenResolver ));
382
-
383
412
foreach ($ this ->properties as $ name => $ property ) {
384
413
if (in_array ($ name , $ properties )) {
385
414
continue ;
0 commit comments