/** * @param Context $context * @return boolean|null */ public function compile(Context $context) { $this->compiled = true; $context->scopePointer = $this->getPointer(); if ($this->statement->getDocComment() === null) { $context->notice('missing-docblock', sprintf('Missing docblock for %s() method', $this->name), $this->statement); } /** * It's not needed to compile empty method via it's abstract */ if ($this->isAbstract()) { /** @var ClassDefinition $scope */ $scope = $context->scope; if (!$scope->isAbstract()) { $context->notice('not-abstract-class-with-abstract-method', 'Class must be an abstract', $this->statement); } return true; } if (count($this->statement->stmts) == 0) { return $context->notice('not-implemented-method', sprintf('Method %s() is not implemented', $this->name), $this->statement); } if (count($this->statement->params) > 0) { /** @var Node\Param $parameter */ foreach ($this->statement->params as $parameter) { $context->addSymbol($parameter->name); } } foreach ($this->statement->stmts as $st) { \PHPSA\nodeVisitorFactory($st, $context); } }
private function modifyDocBlock(ClassMethod $node) { $docComment = $node->getDocComment() ?: new Doc('/** ' . $node->name . ' */'); $docBlock = $this->docBlock->removeParamTags($docComment->getText()); $docBlock = $this->docBlock->addParams($node, $docBlock); $docComment->setText($docBlock); $this->reapplyModifiedNode($node, $docComment); }
/** * @param ClassMethod $methodStmt * @param Context $context * @return bool */ public function pass(ClassMethod $methodStmt, Context $context) { $functionName = $methodStmt->name; if (!$functionName) { return false; } if (substr($functionName, 0, 4) !== 'test') { return false; } if ($methodStmt->getDocComment()) { $phpdoc = $this->docBlockFactory->create($methodStmt->getDocComment()->getText()); if ($phpdoc->hasTag('test')) { $context->notice('test.annotation', 'Annotation @test is not needed when the method is prefixed with test.', $methodStmt); return true; } } return false; }
/** * @param Context $context * @return bool */ public function compile(Context $context) { if ($this->st->getDocComment() === null) { return $context->notice('missing-docblock', sprintf('Missing docblock for %s() method', $this->name), $this->st); } if (count($this->ast) == 0) { return $context->notice('not-implemented-method', sprintf('Method %s() is not implemented', $this->name), $this->st); } if (count($this->st->params) > 0) { /** @var Node\Param $parameter */ foreach ($this->st->params as $parameter) { $context->addSymbol($parameter->name); } } foreach ($this->ast as $st) { $result = \PHPSA\nodeVisitorFactory($st, $context); } }
/** * @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 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]; }
protected function addMethod(ClassMethodNode $node) { $method = new MethodReflection($node->name, $node->getLine()); $method->setModifiers((string) $node->type); $method->setByRef((string) $node->byRef); foreach ($node->params as $param) { $parameter = new ParameterReflection($param->name, $param->getLine()); $parameter->setModifiers((string) $param->type); $parameter->setByRef($param->byRef); if ($param->default) { $parameter->setDefault($this->context->getPrettyPrinter()->prettyPrintExpr($param->default)); } if ((string) $param->type) { $parameter->setHint($this->resolveHint(array(array((string) $param->type, false)))); } $method->addParameter($parameter); } $comment = $this->context->getDocBlockParser()->parse($node->getDocComment(), $this->context, $method); $method->setDocComment($node->getDocComment()); $method->setShortDesc($comment->getShortDesc()); $method->setLongDesc($comment->getLongDesc()); if (!($errors = $comment->getErrors())) { $errors = $this->updateMethodParametersFromTags($method, $comment->getTag('param')); if ($tag = $comment->getTag('return')) { $method->setHint($this->resolveHint($tag[0][0])); $method->setHintDesc($tag[0][1]); } $method->setExceptions($comment->getTag('throws')); $method->setTags($comment->getOtherTags()); } $method->setErrors($errors); if ($this->context->getFilter()->acceptMethod($method)) { $this->context->getClass()->addMethod($method); if ($errors) { $this->context->addErrors((string) $method, $node->getLine(), $errors); } } }
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); }
private function enterClassMethod(Scope $scope, Node\Stmt\ClassMethod $classMethod) : Scope { $fileTypeMap = $this->fileTypeMapper->getTypeMap($scope->getFile()); $phpDocParameterTypes = []; $phpDocReturnType = null; if ($classMethod->getDocComment() !== null) { $docComment = $classMethod->getDocComment()->getText(); $phpDocParameterTypes = TypehintHelper::getPhpDocParameterTypesFromMethod($fileTypeMap, array_map(function (Param $parameter) : string { return $parameter->name; }, $classMethod->params), $docComment); $phpDocReturnType = TypehintHelper::getPhpDocReturnTypeFromMethod($fileTypeMap, $docComment); } return $scope->enterClassMethod($classMethod, $phpDocParameterTypes, $phpDocReturnType); }