Skip to content

Commit ed06e30

Browse files
committed
ClassType: namespace is passed to methods immediately
1 parent 42e818c commit ed06e30

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static function from($from)
8383
}
8484
foreach ($from->getMethods() as $method) {
8585
if ($method->getDeclaringClass() == $from) { // intentionally ==
86-
$class->methods[$method->getName()] = Method::from($method);
86+
$class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
8787
}
8888
}
8989
return $class;
@@ -120,10 +120,6 @@ public function __toString()
120120
return array_map([$this->namespace ?: new PhpNamespace, 'unresolveName'], $arr);
121121
};
122122

123-
foreach ($this->methods as $method) {
124-
$method->setNamespace($this->namespace);
125-
}
126-
127123
return Strings::normalize(
128124
($this->comment ? str_replace("\n", "\n * ", "/**\n" . $this->comment) . "\n */\n" : '')
129125
. ($this->abstract ? 'abstract ' : '')
@@ -472,7 +468,7 @@ public function setMethods(array $methods)
472468
if (!$v instanceof Method) {
473469
throw new Nette\InvalidArgumentException('Argument must be Nette\PhpGenerator\Method[].');
474470
}
475-
$this->methods[$v->getName()] = $v;
471+
$this->methods[$v->getName()] = $v->setNamespace($this->namespace);
476472
}
477473
return $this;
478474
}
@@ -505,7 +501,7 @@ public function getMethod($name)
505501
*/
506502
public function addMethod($name)
507503
{
508-
$method = new Method($name);
504+
$method = (new Method($name))->setNamespace($this->namespace);
509505
if ($this->type === 'interface') {
510506
$method->setVisibility(NULL)->setBody(FALSE);
511507
} else {

0 commit comments

Comments
 (0)