File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace AndreasElia \PostmanGenerator \Processors ;
4
+
5
+ use Illuminate \Support \Str ;
6
+ use PHPStan \PhpDocParser \Ast \PhpDoc \PhpDocTextNode ;
7
+ use PHPStan \PhpDocParser \Lexer \Lexer ;
8
+ use PHPStan \PhpDocParser \Parser \ConstExprParser ;
9
+ use PHPStan \PhpDocParser \Parser \PhpDocParser ;
10
+ use PHPStan \PhpDocParser \Parser \TokenIterator ;
11
+ use PHPStan \PhpDocParser \Parser \TypeParser ;
12
+ use ReflectionFunction ;
13
+ use ReflectionMethod ;
14
+ use Throwable ;
15
+
16
+ class DocBlockProcessor
17
+ {
18
+ public function __invoke (ReflectionMethod |ReflectionFunction $ reflectionMethod ): string
19
+ {
20
+ try {
21
+ $ lexer = new Lexer ;
22
+ $ constExprParser = new ConstExprParser ;
23
+ $ parser = new PhpDocParser (new TypeParser ($ constExprParser ), $ constExprParser );
24
+
25
+ $ description = '' ;
26
+ $ comment = $ reflectionMethod ->getDocComment ();
27
+ $ tokens = new TokenIterator ($ lexer ->tokenize ($ comment ));
28
+ $ phpDocNode = $ parser ->parse ($ tokens );
29
+
30
+ foreach ($ phpDocNode ->children as $ child ) {
31
+ if ($ child instanceof PhpDocTextNode) {
32
+ $ description .= ' ' .$ child ->text ;
33
+ }
34
+ }
35
+
36
+ return Str::squish ($ description );
37
+ } catch (Throwable $ e ) {
38
+ return '' ;
39
+ }
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments