88namespace OpenAPIExtractor ;
99
1010use PhpParser \Node \Stmt \ClassMethod ;
11+ use PhpParser \Node \Stmt \Return_ ;
1112use PHPStan \PhpDocParser \Ast \PhpDoc \DeprecatedTagValueNode ;
1213use PHPStan \PhpDocParser \Ast \PhpDoc \GenericTagValueNode ;
1314use PHPStan \PhpDocParser \Ast \PhpDoc \ParamTagValueNode ;
@@ -45,7 +46,7 @@ public static function parse(string $context,
4546 bool $ isPasswordConfirmation ,
4647 bool $ isCORS ,
4748 ): ControllerMethod {
48- global $ phpDocParser , $ lexer , $ allowMissingDocs ;
49+ global $ phpDocParser , $ lexer , $ nodeFinder , $ allowMissingDocs ;
4950
5051 $ parameters = [];
5152 $ responses = [];
@@ -56,6 +57,9 @@ public static function parse(string $context,
5657 $ methodParameters = $ method ->getParams ();
5758 $ docParameters = [];
5859
60+ $ returnStmtCount = count ($ nodeFinder ->findInstanceOf ($ method ->getStmts (), Return_::class));
61+ $ returnTagCount = 0 ;
62+
5963 $ doc = $ method ->getDocComment ()?->getText();
6064 if ($ doc !== null ) {
6165 $ docNodes = $ phpDocParser ->parse (new TokenIterator ($ lexer ->tokenize ($ doc )))->children ;
@@ -109,6 +113,8 @@ public static function parse(string $context,
109113 }
110114
111115 if ($ docNode ->value instanceof ReturnTagValueNode) {
116+ $ returnTagCount ++;
117+
112118 $ type = $ docNode ->value ->type ;
113119
114120 $ responses = array_merge ($ responses , ResponseType::resolve ($ context . ': @return ' , $ type ));
@@ -136,6 +142,10 @@ public static function parse(string $context,
136142 }
137143 }
138144
145+ if ($ returnStmtCount !== 0 && $ returnTagCount === 0 ) {
146+ Logger::error ($ context , 'Missing @return annotation ' );
147+ }
148+
139149 if (!$ allowMissingDocs ) {
140150 foreach (array_unique (array_map (fn (ControllerMethodResponse $ response ): int => $ response ->statusCode , array_filter ($ responses , fn (?ControllerMethodResponse $ response ): bool => $ response != null ))) as $ statusCode ) {
141151 if ($ statusCode < 500 && (!array_key_exists ($ statusCode , $ responseDescriptions ) || $ responseDescriptions [$ statusCode ] === '' )) {
0 commit comments