/** * @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; }
/** * @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); } }
public function isStatic() : bool { return $this->classMethod->isStatic(); }
/** * @param Node\Stmt\ClassMethod $node */ protected function parseClassMethodNode(Node\Stmt\ClassMethod $node) { $parameters = []; /** @var \PhpParser\Node\Param $param */ foreach ($node->params as $param) { $parameters[] = ['name' => $param->name, 'type' => (string) $param->type, 'isReference' => $param->byRef, 'isVariadic' => $param->variadic, 'isOptional' => $param->default ? true : false]; } $this->structuralElements[$this->currentStructuralElement->namespacedName->toString()]['methods'][] = ['name' => $node->name, 'startLine' => $node->getLine(), 'isPublic' => $node->isPublic(), 'isPrivate' => $node->isPrivate(), 'isProtected' => $node->isProtected(), 'isStatic' => $node->isStatic(), 'returnType' => $node->getReturnType(), 'parameters' => $parameters, 'docComment' => $node->getDocComment() ? $node->getDocComment()->getText() : null]; }
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); }
public function store_class_method(Node\Stmt\Class_ $class, Node\Stmt\ClassMethod $method) { $parameters = array_map(function ($param) { return array('name' => $param->name, 'default' => !empty($param->default), 'type' => ltrim((string) $param->type, '\\')); }, $method->getParams()); $access = array_keys(array_filter(array('public' => $method->isPublic(), 'protected' => $method->isProtected(), 'private' => $method->isPrivate())))[0]; $return_types = array(); $description = ''; if ($comments = $method->getAttribute('comments')) { $phpdoc = new DocBlock($comments[0]->getText()); $description = $phpdoc->getShortDescription(); if ($return = $phpdoc->getTagsByName('return')) { $return_types = array_map('ltrim', explode('|', $return[0]->getType()), array('\\')); } // short circuit @ignore functions if ($phpdoc->hasTag('ignore')) { return; } } $this->store_model('methods', array('method' => $method->name, 'namespace' => !empty($method->namespacedName) ? implode('\\', array_slice($method->namespacedName->parts, 0, -1)) : '', 'file' => $this->_current_file, 'line' => $method->getLine(), 'description' => $description, 'return_types' => json_encode($return_types), 'parameters' => json_encode($parameters), 'access' => $access, 'is_static' => $method->isStatic(), 'class' => $class->name)); }
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)); }