77
88namespace OpenAPIExtractor ;
99
10+ use PhpParser \Node \Expr \MethodCall ;
11+ use PhpParser \Node \Expr \PropertyFetch ;
12+ use PhpParser \Node \Expr \Variable ;
1013use PhpParser \Node \Stmt \ClassMethod ;
1114use PhpParser \Node \Stmt \Return_ ;
1215use PHPStan \PhpDocParser \Ast \PhpDoc \DeprecatedTagValueNode ;
@@ -23,13 +26,15 @@ class ControllerMethod {
2326
2427 /**
2528 * @param ControllerMethodParameter[] $parameters
29+ * @param list<string> $requestHeaders
2630 * @param list<ControllerMethodResponse|null> $responses
2731 * @param OpenApiType[] $returns
2832 * @param array<int, string> $responseDescription
2933 * @param string[] $description
3034 */
3135 public function __construct (
3236 public array $ parameters ,
37+ public array $ requestHeaders ,
3338 public array $ responses ,
3439 public array $ responseDescription ,
3540 public array $ description ,
@@ -274,7 +279,18 @@ public static function parse(string $context,
274279 Logger::warning ($ context , 'Summary ends with a punctuation mark ' );
275280 }
276281
277- return new ControllerMethod ($ parameters , $ responses , $ responseDescriptions , $ methodDescription , $ methodSummary , $ isDeprecated );
282+ $ headers = [];
283+ foreach ($ nodeFinder ->findInstanceOf ($ method ->getStmts (), MethodCall::class) as $ methodCall ) {
284+ if ($ methodCall ->var instanceof PropertyFetch &&
285+ $ methodCall ->var ->var instanceof Variable &&
286+ $ methodCall ->var ->var ->name === 'this ' &&
287+ $ methodCall ->var ->name ->name === 'request ' &&
288+ $ methodCall ->name ->name === 'getHeader ' ) {
289+ $ headers [] = Helpers::exprToValue ($ context . ': getHeader ' , $ methodCall ->args [0 ]->value );
290+ }
291+ }
292+
293+ return new ControllerMethod ($ parameters , array_unique ($ headers ), $ responses , $ responseDescriptions , $ methodDescription , $ methodSummary , $ isDeprecated );
278294 }
279295
280296}
0 commit comments