コード例 #1
0
 /**
  * @param FunctionLike $node A PHP-Parser Node function-like object to resolve return types of
  *
  * @return array A array of the return types, or empty array if no return comment exists
  */
 public static function parseNode(FunctionLike $node)
 {
     /** @var Comment[] $returnComments */
     $returnComments = self::filterComments($node->getAttribute("comments", []));
     if (empty($returnComments)) {
         return [];
         // TODO: void? mixed? Maybe verify that comments tag exists?
     }
     /** @var DocBlock\Tag $lastReturnKeyword If multiple "@return" tags, only the last one in last DocBlock used. */
     $lastReturnKeyword = last((new DocBlock(last($returnComments)->getReformattedText()))->getTagsByName("return"));
     // Everything after the tag (after the appending space), is tag content.
     return self::parse(DocTypeNormaliser::sanitise($lastReturnKeyword->getContent()));
 }
コード例 #2
0
ファイル: DocVarTypeParser.php プロジェクト: sekjun9878/elphp
 /**
  * @param Node $node A PHP-Parser Node object to parse var comments of
  *
  * @return array An array of the types, or empty array if no return comment exists
  */
 public static function parseNode(Node $node)
 {
     /** @var Comment[] $varComments */
     $varComments = self::filterComments($node->getAttribute("comments", []));
     if (empty($varComments)) {
         return [];
     }
     return array_filter(array_unique(array_map(function (DocBlock\Tag $var) use($node) {
         $var = DocTypeNormaliser::sanitise($var->getContent());
         return self::resolveImplicitVarName(self::parse($var), $node);
     }, array_flatten(array_map(function (Comment $comment) {
         return (new DocBlock($comment->getReformattedText()))->getTagsByName("var");
     }, $varComments))), SORT_REGULAR), function ($element) {
         var_dump($element);
         return $element['name'] !== null;
         // Filter null names - see self::resolveImplicitVarName()
     });
 }
コード例 #3
0
 /**
  * @param FunctionLike $node A PHP-Parser Node function-like object to resolve param types of
  *
  * @return array A array of the param arguments and types (if possible), or empty array if no arguments accepted
  */
 public static function parseNode(FunctionLike $node)
 {
     /** @var Comment[] $paramComments */
     $paramComments = self::filterComments($node->getAttribute("comments", []));
     if (empty($paramComments)) {
         return [];
     }
     $posCount = 0;
     // Used for positional @param tags e.g. without $varName
     $params = array_unique(array_map(function (DocBlock\Tag $param) use(&$posCount) {
         $param = DocTypeNormaliser::sanitise($param->getContent());
         $param = self::parse($param, $posCount++);
         // Below code can be used to selectively increment posCount - remove ++ above
         // $posCount = ($param["name"]{0} === "#") ? $posCount + 1 : $posCount;
         return $param;
     }, array_flatten(array_map(function (Comment $comment) {
         return (new DocBlock($comment->getReformattedText()))->getTagsByName("param");
     }, $paramComments))), SORT_REGULAR);
     // ["$var" => ["pos" => 0, "name" => "$var", "type" => ["bool", "\Class"]]]
     // ["#1" => ["pos" => 1, "name" => "#1", "type" => ["bool", "\Class"]]]
     return array_combine(array_map(function ($param) {
         return $param["name"];
     }, $params), $params);
 }