Skip to content

Commit 224730a

Browse files
committed
ClassType, Method: class types are not resolved when namespace is not specified [#21]
Fixed BC break introduced in v2.3.3
1 parent c0b2934 commit 224730a

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ public function __toString()
120120
. ";\n";
121121
}
122122

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

128128
return Strings::normalize(

src/PhpGenerator/Method.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,11 @@ public function __construct($name = NULL)
103103
*/
104104
public function __toString()
105105
{
106-
$namespace = $this->namespace ?: new PhpNamespace;
107106
$parameters = array();
108107
foreach ($this->parameters as $param) {
109108
$variadic = $this->variadic && $param === end($this->parameters);
110-
111-
$parameters[] = ($param->getTypeHint() ? $namespace->unresolveName($param->getTypeHint()) . ' ' : '')
109+
$hint = $param->getTypeHint();
110+
$parameters[] = ($hint ? ($this->namespace ? $this->namespace->unresolveName($hint) : $hint) . ' ' : '')
112111
. ($param->isReference() ? '&' : '')
113112
. ($variadic ? '...' : '')
114113
. '$' . $param->getName()
@@ -129,7 +128,7 @@ public function __toString()
129128
. ' ' . $this->name
130129
. '(' . implode(', ', $parameters) . ')'
131130
. ($this->uses ? ' use (' . implode(', ', $uses) . ')' : '')
132-
. ($this->returnType ? ': ' . $namespace->unresolveName($this->returnType) : '')
131+
. ($this->returnType ? ': ' . ($this->namespace ? $this->namespace->unresolveName($this->returnType) : $this->returnType) : '')
133132
. ($this->abstract || $this->body === FALSE ? ';'
134133
: ($this->name ? "\n" : ' ') . "{\n" . Nette\Utils\Strings::indent(ltrim(rtrim($this->body) . "\n"), 1) . '}');
135134
}

tests/PhpGenerator/PhpNamespace.fqn1.expect

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
class Example extends ParentClass implements One, Two
1+
class Example extends \ParentClass implements One, \Two
22
{
33
use Three;
4-
use Four;
4+
use \Four;
55

66

77
public function one(): One
88
{
99
}
1010

1111

12-
public function two(One $one, Two $two): Two
12+
public function two(One $one, \Two $two): \Two
1313
{
1414
}
1515

0 commit comments

Comments
 (0)