Skip to content

Commit

Permalink
ClassType, Method: class types are not resolved when namespace is not…
Browse files Browse the repository at this point in the history
… specified [#21]

Fixed BC break introduced in v2.3.3
  • Loading branch information
dg committed Nov 29, 2015
1 parent c0b2934 commit 224730a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/PhpGenerator/ClassType.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public function __toString()
. ";\n";
}

$namespace = $this->namespace ?: new PhpNamespace;
$namespace = $this->namespace;
$mapper = function (array $arr) use ($namespace) {
return array_map(array($namespace, 'unresolveName'), $arr);
return $namespace ? array_map(array($namespace, 'unresolveName'), $arr) : $arr;
};

return Strings::normalize(
Expand Down
7 changes: 3 additions & 4 deletions src/PhpGenerator/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ public function __construct($name = NULL)
*/
public function __toString()
{
$namespace = $this->namespace ?: new PhpNamespace;
$parameters = array();
foreach ($this->parameters as $param) {
$variadic = $this->variadic && $param === end($this->parameters);

$parameters[] = ($param->getTypeHint() ? $namespace->unresolveName($param->getTypeHint()) . ' ' : '')
$hint = $param->getTypeHint();
$parameters[] = ($hint ? ($this->namespace ? $this->namespace->unresolveName($hint) : $hint) . ' ' : '')
. ($param->isReference() ? '&' : '')
. ($variadic ? '...' : '')
. '$' . $param->getName()
Expand All @@ -129,7 +128,7 @@ public function __toString()
. ' ' . $this->name
. '(' . implode(', ', $parameters) . ')'
. ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '')
. ($this->returnType ? ': ' . $namespace->unresolveName($this->returnType) : '')
. ($this->returnType ? ': ' . ($this->namespace ? $this->namespace->unresolveName($this->returnType) : $this->returnType) : '')
. ($this->abstract || $this->body === FALSE ? ';'
: ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(ltrim(rtrim($this->body) . "\n"), 1) . '}');
}
Expand Down
6 changes: 3 additions & 3 deletions tests/PhpGenerator/PhpNamespace.fqn1.expect
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Example extends ParentClass implements One, Two
class Example extends \ParentClass implements One, \Two
{
use Three;
use Four;
use \Four;


public function one(): One
{
}


public function two(One $one, Two $two): Two
public function two(One $one, \Two $two): \Two
{
}

Expand Down

0 comments on commit 224730a

Please sign in to comment.