Beispiel #1
0
 /**
  * @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()
     });
 }
 /**
  * @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);
 }