/** * get General information about the function * doc block, declared line/file etc. * * @return array **/ public function getInfo() { $info = array('name' => $this->getName(), 'comment' => $this->_parseComment($this->getDocComment()), 'declaredInFile' => $this->getFileName(), 'startLine' => $this->getStartLine(), 'endLine' => $this->getEndLine(), 'internal' => $this->isInternal()); $this->info = $info; $this->info['signature'] = DocblockTools::makeFunctionSignature($this); return $this->info; }
/** * getMethods * * Gets all current methods for object with documentation. * Returns an array with the following structure * 'name' => name of the method * 'access' => level of access to the method * 'args' => array of arguments that the method takes. Args are removed from comment['tags'] as they don't need to be repeated * 'comment' => keyed array see cleanComment * * @see $this->_parseComment * @return array multi-dimensional array of methods and their attributes **/ public function getMethods() { $methods = parent::getMethods(); foreach ($methods as $method) { $doc = $this->_parseComment($method->getDocComment()); if (isset($doc['tags']['param'])) { $doc['tags']['param'] = (array) $doc['tags']['param']; } $met = array('name' => $method->getName(), 'comment' => $doc, 'startLine' => $method->getStartLine(), 'declaredInClass' => $method->getDeclaringClass()->getName(), 'declaredInFile' => $method->getDeclaringClass()->getFileName(), 'signature' => DocblockTools::makeFunctionSignature($method), 'isStatic' => $method->isStatic()); $params = $method->getParameters(); $args = array(); foreach ($params as $param) { $type = $description = null; if (isset($met['comment']['tags']['param'][$param->name])) { extract($met['comment']['tags']['param'][$param->name]); } $args[$param->name] = array('optional' => $param->isOptional(), 'default' => null, 'hasDefault' => false, 'position' => $param->getPosition(), 'type' => $type, 'comment' => $description); if ($param->isDefaultValueAvailable()) { $args[$param->name]['default'] = $param->getDefaultValue(); $args[$param->name]['hasDefault'] = true; } } unset($met['comment']['tags']['param']); $met['args'] = $args; if ($method->isPublic()) { $met['access'] = 'public'; if (isset($doc['tags']['access'])) { $met['access'] = $doc['tags']['access']; } } if ($method->isPrivate()) { $met['access'] = 'private'; } if ($method->isProtected()) { $met['access'] = 'protected'; } $this->methods[] = $met; } return $this->methods; }
/** * test function signature making * * @return void **/ function testMakeFunctionSignature() { App::import('Lib', array('ApiGenerator.FunctionDocumentor', 'ApiGenerator.ClassDocumentor')); $Func = new FunctionDocumentor('count'); $result = DocblockTools::makeFunctionSignature($Func); $expected = 'count( $var, $mode )'; $this->assertEqual($result, $expected); $Class = new ClassDocumentor('ClassDocumentor'); $function = $Class->getMethod('_parseComment'); $result = DocblockTools::makeFunctionSignature($function); $expected = '_parseComment( $comments )'; $this->assertEqual($result, $expected); }