Skip to content

Commit 36f8baf

Browse files
committed
PhpNamespace::unresolveName() supports for build-in types
1 parent 77b39dc commit 36f8baf

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/PhpGenerator/Method.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@ public static function from($from)
8989
*/
9090
public function __toString()
9191
{
92-
static $builtinTypes = array('array', 'self', 'parent', 'callable', NULL);
9392
$parameters = array();
9493
foreach ($this->parameters as $param) {
9594
$variadic = $this->variadic && $param === end($this->parameters);
96-
$hint = !$this->namespace || in_array($param->getTypeHint(), $builtinTypes, TRUE)
97-
? $param->getTypeHint()
98-
: $this->namespace->unresolveName($param->getTypeHint());
95+
$hint = $this->namespace
96+
? $this->namespace->unresolveName((string) $param->getTypeHint())
97+
: $param->getTypeHint();
9998

10099
$parameters[] = ($hint ? $hint . ' ' : '')
101100
. ($param->isReference() ? '&' : '')

src/PhpGenerator/PhpNamespace.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public function addUse($name, $alias = NULL, &$aliasOut = NULL)
134134
*/
135135
public function unresolveName($name)
136136
{
137+
if (in_array(strtolower($name), array('self', 'parent', 'array', 'callable', 'string', 'bool', 'float', 'int', ''), TRUE)) {
138+
return $name;
139+
}
137140
$name = ltrim($name, '\\');
138141
$res = NULL;
139142
$lower = strtolower($name);

tests/PhpGenerator/PhpNamespace.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Assert::same('\Bar', $namespace->unresolveName('Bar'));
2121
Assert::same('C', $namespace->unresolveName('bar\C'));
2222
Assert::same('C\D', $namespace->unresolveName('Bar\C\D'));
2323

24+
foreach (array('String', 'string', 'int', 'float', 'bool', 'array', 'callable', 'self', 'parent', '') as $type) {
25+
Assert::same($type, $namespace->unresolveName($type));
26+
}
27+
2428

2529
$classA = $namespace->addClass('A');
2630
Assert::same($namespace, $classA->getNamespace());

0 commit comments

Comments
 (0)