Skip to content

Commit 726e022

Browse files
committed
refactoring
1 parent c122792 commit 726e022

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,10 @@ public function __toString()
116116
. ";\n";
117117
}
118118

119-
$extends = (array) $this->extends;
120-
$implements = $this->implements;
121-
$traits = $this->traits;
122-
if ($this->namespace) {
123-
$extends = array_map(array($this->namespace, 'unresolveName'), $extends);
124-
$implements = array_map(array($this->namespace, 'unresolveName'), $implements);
125-
$traits = array_map(array($this->namespace, 'unresolveName'), $traits);
126-
}
119+
$namespace = $this->namespace ?: new PhpNamespace;
120+
$mapper = function (array $arr) use ($namespace) {
121+
return array_map(array($namespace, 'unresolveName'), $arr);
122+
};
127123

128124
foreach ($this->methods as $method) {
129125
$method->setNamespace($this->namespace);
@@ -135,11 +131,11 @@ public function __toString()
135131
. ($this->final ? 'final ' : '')
136132
. $this->type . ' '
137133
. $this->name . ' '
138-
. ($extends ? 'extends ' . implode(', ', $extends) . ' ' : '')
139-
. ($implements ? 'implements ' . implode(', ', $implements) . ' ' : '')
134+
. ($this->extends ? 'extends ' . implode(', ', $mapper((array) $this->extends)) . ' ' : '')
135+
. ($this->implements ? 'implements ' . implode(', ', $mapper($this->implements)) . ' ' : '')
140136
. "\n{\n"
141137
. Strings::indent(
142-
($traits ? 'use ' . implode(";\nuse ", $traits) . ";\n\n" : '')
138+
($this->traits ? 'use ' . implode(";\nuse ", $mapper($this->traits)) . ";\n\n" : '')
143139
. ($this->consts ? implode('', $consts) . "\n" : '')
144140
. ($this->properties ? implode("\n", $properties) . "\n" : '')
145141
. ($this->methods ? "\n" . implode("\n\n\n", $this->methods) . "\n\n" : ''), 1)

src/PhpGenerator/Method.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,12 @@ public function __construct($name = NULL)
9797
*/
9898
public function __toString()
9999
{
100+
$namespace = $this->namespace ?: new PhpNamespace;
100101
$parameters = array();
101102
foreach ($this->parameters as $param) {
102103
$variadic = $this->variadic && $param === end($this->parameters);
103-
$hint = $this->namespace
104-
? $this->namespace->unresolveName((string) $param->getTypeHint())
105-
: $param->getTypeHint();
106104

107-
$parameters[] = ($hint ? $hint . ' ' : '')
105+
$parameters[] = ($param->getTypeHint() ? $namespace->unresolveName($param->getTypeHint()) . ' ' : '')
108106
. ($param->isReference() ? '&' : '')
109107
. ($variadic ? '...' : '')
110108
. '$' . $param->getName()

0 commit comments

Comments
 (0)