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); }
public function testEmptyMethod() { $method = new PhpMethod(self::METHOD); $method->generateDocblock(); $this->assertTrue($method->getDocblock()->isEmpty()); }
public function visitMethod(PhpMethod $method) { $this->visitDocblock($method->getDocblock()); if ($method->isAbstract()) { $this->writer->write('abstract '); } $this->writer->write($method->getVisibility() . ' '); if ($method->isStatic()) { $this->writer->write('static '); } $this->writer->write('function '); if ($method->isReferenceReturned()) { $this->writer->write('& '); } $this->writer->write($method->getName() . '('); $this->writeParameters($method->getParameters()); $this->writer->write(")"); $this->writeFunctionReturnType($method->getType()); if ($method->isAbstract() || $method->getParent() instanceof PhpInterface) { $this->writer->write(";\n\n"); return; } $this->writer->writeln(' {')->indent()->writeln(trim($method->getBody()))->outdent()->rtrim()->write("}\n\n"); }