Skip to content

Commit 912fa94

Browse files
committed
ClassType::__toString() refactoring
1 parent 14dce1c commit 912fa94

File tree

1 file changed

+9
-20
lines changed

1 file changed

+9
-20
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,15 @@ public function __toString()
125125
. ";\n";
126126
}
127127

128-
$extends = $implements = $traits = array();
128+
$extends = (array) $this->extends;
129+
$implements = $this->implements;
130+
$traits = $this->traits;
129131
if ($this->namespace) {
130-
foreach ((array) $this->extends as $name) {
131-
$extends[] = $this->namespace->unresolveName($name);
132+
$extends = array_map(array($this->namespace, 'unresolveName'), $extends);
133+
$implements = array_map(array($this->namespace, 'unresolveName'), $implements);
134+
$traits = array_map(array($this->namespace, 'unresolveName'), $traits);
132135
}
133136

134-
foreach ((array) $this->implements as $name) {
135-
$implements[] = $this->namespace->unresolveName($name);
136-
}
137-
138-
foreach ((array) $this->traits as $name) {
139-
$traits[] = $this->namespace->unresolveName($name);
140-
}
141-
142-
} else {
143-
$extends = (array) $this->extends;
144-
$implements = (array) $this->implements;
145-
$traits = (array) $this->traits;
146-
}
147-
148137
foreach ($this->methods as $method) {
149138
$method->setNamespace($this->namespace);
150139
}
@@ -155,11 +144,11 @@ public function __toString()
155144
. ($this->final ? 'final ' : '')
156145
. $this->type . ' '
157146
. $this->name . ' '
158-
. ($this->extends ? 'extends ' . implode(', ', $extends) . ' ' : '')
159-
. ($this->implements ? 'implements ' . implode(', ', $implements) . ' ' : '')
147+
. ($extends ? 'extends ' . implode(', ', $extends) . ' ' : '')
148+
. ($implements ? 'implements ' . implode(', ', $implements) . ' ' : '')
160149
. "\n{\n"
161150
. Strings::indent(
162-
($this->traits ? 'use ' . implode(', ', $traits) . ";\n\n" : '')
151+
($traits ? 'use ' . implode(', ', $traits) . ";\n\n" : '')
163152
. ($this->consts ? implode('', $consts) . "\n" : '')
164153
. ($this->properties ? implode("\n", $properties) . "\n" : '')
165154
. ($this->methods ? "\n" . implode("\n\n\n", $this->methods) . "\n\n" : ''), 1)

0 commit comments

Comments
 (0)