/**
* Returns a method in the current specification from a DOMNode
*
* @param \DOMNode $node A DOMNode
*
* @return Method
*/
public function getMethod(\DOMNode $node)
{
$crawler = new Crawler($node);
$name = $crawler->attr('name');
// Initialize
$method = new Method($name);
// Type
$method->setType(preg_match('/(^(get|is)|ToString$)/', $name) ? Method::TYPE_ACCESSOR : Method::TYPE_ACTION);
// Description
$descriptions = $crawler->filterXPath('//comment');
if (count($descriptions) !== 1) {
throw new \Exception('Only one comment expected');
}
$descriptions->rewind();
$description = $this->getInner($descriptions->current());
$method->setDescription($description);
// Parameters
foreach ($crawler->filterXPath('//parameter') as $node) {
$method->addParameter($this->getParameter($node));
}
// Return
$returnNodes = $crawler->filterXPath('//return');
if (count($returnNodes) > 1) {
throw new \Exception("Should not be more than one return node");
} elseif (count($returnNodes) == 1) {
$returnNodes->rewind();
list($type, $description) = $this->getReturn($returnNodes->current());
$method->setReturnType($type);
$method->setReturnDescription($description);
}
return $method;
}