From ed06e308076be36e56f20e312c0b67bc4a336674 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Tue, 1 Sep 2015 00:24:04 +0200 Subject: [PATCH] ClassType: namespace is passed to methods immediately --- src/PhpGenerator/ClassType.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/PhpGenerator/ClassType.php b/src/PhpGenerator/ClassType.php index dc32bd22..5aa3be68 100644 --- a/src/PhpGenerator/ClassType.php +++ b/src/PhpGenerator/ClassType.php @@ -83,7 +83,7 @@ public static function from($from) } foreach ($from->getMethods() as $method) { if ($method->getDeclaringClass() == $from) { // intentionally == - $class->methods[$method->getName()] = Method::from($method); + $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace); } } return $class; @@ -120,10 +120,6 @@ public function __toString() return array_map([$this->namespace ?: new PhpNamespace, 'unresolveName'], $arr); }; - foreach ($this->methods as $method) { - $method->setNamespace($this->namespace); - } - return Strings::normalize( ($this->comment ? str_replace("\n", "\n * ", "/**\n" . $this->comment) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') @@ -472,7 +468,7 @@ public function setMethods(array $methods) if (!$v instanceof Method) { throw new Nette\InvalidArgumentException('Argument must be Nette\PhpGenerator\Method[].'); } - $this->methods[$v->getName()] = $v; + $this->methods[$v->getName()] = $v->setNamespace($this->namespace); } return $this; } @@ -505,7 +501,7 @@ public function getMethod($name) */ public function addMethod($name) { - $method = new Method($name); + $method = (new Method($name))->setNamespace($this->namespace); if ($this->type === 'interface') { $method->setVisibility(NULL)->setBody(FALSE); } else {