@@ -30,7 +30,7 @@ final class ContractParser
3030 /**
3131 * Cache for resolved contract metadata.
3232 *
33- * @var array<string, array{types: array<string, TypeNode>, templates: array<string, TemplateTagValueNode>, classTemplates: array<string, TemplateTagValueNode>, return: ?TypeNode, aliases: array<string, TypeNode>}>
33+ * @var array<string, array{types: array<string, TypeNode>, templates: array<string, TemplateTagValueNode>, classTemplates: array<string, TemplateTagValueNode>, return: ?TypeNode, aliases: array<string, TypeNode>, hasParamContract: bool, hasReturnContract: bool }>
3434 */
3535 private static array $ cache = [];
3636
@@ -72,7 +72,7 @@ public static function reset(): void
7272 /**
7373 * Parses PHPDoc contracts for a function or class method.
7474 *
75- * @return array{types: array<string, TypeNode>, templates: array<string, TemplateTagValueNode>, classTemplates: array<string, TemplateTagValueNode>, return: ?TypeNode, aliases: array<string, TypeNode>}
75+ * @return array{types: array<string, TypeNode>, templates: array<string, TemplateTagValueNode>, classTemplates: array<string, TemplateTagValueNode>, return: ?TypeNode, aliases: array<string, TypeNode>, hasParamContract: bool, hasReturnContract: bool }
7676 */
7777 public static function parse (string $ function ): array
7878 {
@@ -100,17 +100,35 @@ public static function parse(string $function): array
100100 'classTemplates ' => $ classTemplates ,
101101 'return ' => null ,
102102 'aliases ' => $ aliases ,
103+ 'hasParamContract ' => false ,
104+ 'hasReturnContract ' => false ,
103105 ];
104106 }
105107 } else {
106- $ contract = ['types ' => [], 'templates ' => [], 'classTemplates ' => [], 'return ' => null , 'aliases ' => []];
108+ $ contract = [
109+ 'types ' => [],
110+ 'templates ' => [],
111+ 'classTemplates ' => [],
112+ 'return ' => null ,
113+ 'aliases ' => [],
114+ 'hasParamContract ' => false ,
115+ 'hasReturnContract ' => false ,
116+ ];
107117 }
108118 } else {
109119 $ ref = new \ReflectionFunction ($ function );
110120 $ contract = self ::parseFunction ($ ref );
111121 }
112122 } catch (\ReflectionException $ e ) {
113- $ contract = ['types ' => [], 'templates ' => [], 'classTemplates ' => [], 'return ' => null , 'aliases ' => []];
123+ $ contract = [
124+ 'types ' => [],
125+ 'templates ' => [],
126+ 'classTemplates ' => [],
127+ 'return ' => null ,
128+ 'aliases ' => [],
129+ 'hasParamContract ' => false ,
130+ 'hasReturnContract ' => false ,
131+ ];
114132 }
115133
116134 return self ::$ cache [$ function ] = $ contract ;
@@ -436,7 +454,7 @@ public static function parseClassAliases(string $className): array
436454 /**
437455 * Orchestrates parsing for class methods across the inheritance hierarchy.
438456 *
439- * @return array{types: array<string, TypeNode>, templates: array<string, TemplateTagValueNode>, classTemplates: array<string, TemplateTagValueNode>, return: ?TypeNode, aliases: array<string, TypeNode>}
457+ * @return array{types: array<string, TypeNode>, templates: array<string, TemplateTagValueNode>, classTemplates: array<string, TemplateTagValueNode>, return: ?TypeNode, aliases: array<string, TypeNode>, hasParamContract: bool, hasReturnContract: bool }
440458 */
441459 private static function parseMethod (\ReflectionMethod $ ref ): array
442460 {
@@ -459,13 +477,15 @@ private static function parseMethod(\ReflectionMethod $ref): array
459477 'classTemplates ' => $ classTemplates ,
460478 'return ' => $ returnType ,
461479 'aliases ' => $ aliases ,
480+ 'hasParamContract ' => \count ($ types ) > 0 ,
481+ 'hasReturnContract ' => $ returnType !== null ,
462482 ];
463483 }
464484
465485 /**
466486 * Orchestrates parsing for standalone global or namespaced functions.
467487 *
468- * @return array{types: array<string, TypeNode>, templates: array<string, TemplateTagValueNode>, classTemplates: array<string, TemplateTagValueNode>, return: ?TypeNode, aliases: array<string, TypeNode>}
488+ * @return array{types: array<string, TypeNode>, templates: array<string, TemplateTagValueNode>, classTemplates: array<string, TemplateTagValueNode>, return: ?TypeNode, aliases: array<string, TypeNode>, hasParamContract: bool, hasReturnContract: bool }
469489 */
470490 private static function parseFunction (\ReflectionFunction $ ref ): array
471491 {
@@ -482,6 +502,8 @@ private static function parseFunction(\ReflectionFunction $ref): array
482502 'classTemplates ' => [],
483503 'return ' => null ,
484504 'aliases ' => [],
505+ 'hasParamContract ' => false ,
506+ 'hasReturnContract ' => false ,
485507 ];
486508 }
487509
@@ -520,6 +542,8 @@ private static function parseFunction(\ReflectionFunction $ref): array
520542 'classTemplates ' => [],
521543 'return ' => $ returnType ,
522544 'aliases ' => $ aliases ,
545+ 'hasParamContract ' => \count ($ types ) > 0 ,
546+ 'hasReturnContract ' => $ returnType !== null ,
523547 ];
524548 }
525549
@@ -846,4 +870,4 @@ public static function substituteAliases(TypeNode $node, array $aliases): TypeNo
846870
847871 return $ node ;
848872 }
849- }
873+ }
0 commit comments