/** * @param string * @return Method */ public function addMethod($name) { $method = new Method($name); if ($this->type === 'interface') { $method->setVisibility(NULL)->setBody(FALSE); } else { $method->setVisibility('public'); } return $this->methods[$name] = $method->setNamespace($this->namespace); }
/** * @param \ReflectionMethod $from * @param Code\Method $method * @throws \ReflectionException * @return Code\Method */ public static function expandTypeHints(\ReflectionMethod $from, Code\Method $method) { $parameters = $method->getParameters(); /** @var Code\Parameter[] $parameters */ foreach ($from->getParameters() as $paramRefl) { try { $parameters[$paramRefl->getName()]->setTypeHint($paramRefl->isArray() ? 'array' : ($paramRefl->getClass() ? '\\' . $paramRefl->getClass()->getName() : '')); } catch (\ReflectionException $e) { if (preg_match('#Class (.+) does not exist#', $e->getMessage(), $m)) { $parameters[$paramRefl->getName()]->setTypeHint('\\' . $m[1]); } else { throw $e; } } } $method->setParameters($parameters); if (!$method->getVisibility()) { $method->setVisibility('public'); } return $method; }