public function visitMethod(ClassMethod $node) { $m = new PhpMethod($node->name); $m->setAbstract($node->isAbstract()); $m->setFinal($node->isFinal()); $m->setVisibility($this->getVisibility($node)); $m->setStatic($node->isStatic()); $m->setReferenceReturned($node->returnsByRef()); // docblock if (($doc = $node->getDocComment()) !== null) { $m->setDocblock($doc->getReformattedText()); $docblock = $m->getDocblock(); $m->setDescription($docblock->getShortDescription()); $m->setLongDescription($docblock->getLongDescription()); } // params $params = $m->getDocblock()->getTags('param'); foreach ($node->params as $param) { /* @var $param Param */ $p = new PhpParameter(); $p->setName($param->name); $p->setPassedByReference($param->byRef); if (is_string($param->type)) { $p->setType($param->type); } else { if ($param->type instanceof Name) { $p->setType(implode('\\', $param->type->parts)); } } $this->parseValue($p, $param); $tag = $params->find($p, function (ParamTag $t, $p) { return $t->getVariable() == '$' . $p->getName(); }); if ($tag !== null) { $p->setType($tag->getType(), $tag->getDescription()); } $m->addParameter($p); } // return type and description $returns = $m->getDocblock()->getTags('return'); if ($returns->size() > 0) { $return = $returns->get(0); $m->setType($return->getType(), $return->getDescription()); } // body $stmts = $node->getStmts(); if (is_array($stmts) && count($stmts)) { $prettyPrinter = new PrettyPrinter(); $m->setBody($prettyPrinter->prettyPrint($stmts)); } $this->struct->setMethod($m); }
private function getMethodNodeSignature(Node\Stmt\ClassMethod $node) { if ($node->isPublic()) { $accessModifier = FunctionSignature::ACCESS_PUBLIC; } elseif ($node->isProtected()) { $accessModifier = FunctionSignature::ACCESS_PROTECTED; } else { $accessModifier = FunctionSignature::ACCESS_PRIVATE; } if ($node->isFinal()) { $polymorphModifier = FunctionSignature::POLYMORPH_FINAL; } elseif ($node->isAbstract()) { $polymorphModifier = FunctionSignature::POLYMORPH_ABSTRACT; } else { $polymorphModifier = null; } return FunctionSignature::method($node->byRef, $accessModifier, $polymorphModifier, $node->isStatic(), $node->name, $this->getParameterExpressions($node->params)); }
/** * @param \PhpParser\Node\Stmt\ClassMethod $node */ private function processMethod(\PhpParser\Node\Stmt\ClassMethod $node) { /** @var $method \TheSeer\phpDox\Collector\MethodObject */ $method = $this->unit->addMethod($node->name); $method->setStartLine($node->getAttribute('startLine')); $method->setEndLine($node->getAttribute('endLine')); $method->setAbstract($node->isAbstract()); $method->setFinal($node->isFinal()); $method->setStatic($node->isStatic()); $visibility = 'public'; if ($node->isPrivate()) { $visibility = 'private'; } elseif ($node->isProtected()) { $visibility = 'protected'; } $method->setVisibility($visibility); $docComment = $node->getDocComment(); if ($docComment !== NULL) { $block = $this->dockblocParser->parse($docComment, $this->aliasMap); $method->setDocBlock($block); } $this->processMethodParams($method, $node->params); if ($node->stmts) { $this->processInlineComments($method, $node->stmts); } }
/** * @param ClassMethod $node * * @return RefMethod */ private function createMethod(ClassMethod $node) { $ref = new RefMethod(); $ref->class = $this->class; $ref->name = $node->name; if ($node->isPrivate()) { $ref->visibility = Visibility::IS_PRIVATE; } elseif ($node->isProtected()) { $ref->visibility = Visibility::IS_PROTECTED; } elseif ($node->isPublic()) { $ref->visibility = Visibility::IS_PUBLIC; } $ref->isStatic = $node->isStatic(); $ref->isAbstract = $node->isAbstract(); $ref->isFinal = $node->isFinal(); $ref->startLine = $node->getLine(); $ref->docComment = $this->createDocComment($node); $ref->returnType = $this->getTypeName($node->getReturnType()); foreach ($node->getParams() as $param) { $param = $this->createParam($param, $ref->docComment); $ref->params[$param->name] = $param; } return $ref; }
public function addMethod(ClassMethodNode $node) { $method = new ReflectionMethod($node->name); $method->setStartLine((int) $node->getAttribute('startLine')); $method->setEndLine((int) $node->getAttribute('endLine')); $method->setDocComment((string) $node->getDocComment()); $method->setReturnsByRef((bool) $node->returnsByRef()); $method->setFinal((bool) $node->isFinal()); $method->setStatic((bool) $node->isStatic()); $this->addFunctionLikeParameters($method, $node->params); // All functions in an interface are implicitly abstract. There is no need to use the abstract keyword when declaring the function. if ($this->context->getReflection() instanceof ReflectionInterface) { $method->setAbstract(true); } else { $method->setAbstract((bool) $node->isAbstract()); } if ($node->isPrivate()) { $method->setVisibility(ReflectionMethod::IS_PRIVATE); } elseif ($node->isProtected()) { $method->setVisibility(ReflectionMethod::IS_PROTECTED); } else { $method->setVisibility(ReflectionMethod::IS_PUBLIC); } $this->context->getReflection()->addMethod($method); $this->context->enterFunctionLike($method); }