Skip to content

Commit 08ce376

Browse files
committed
rearrange code
1 parent d160545 commit 08ce376

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

src/Model/RenderJob.php

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,14 @@ protected function generateModelDirectory(string $destination, string $classPath
122122
*/
123123
protected function renderClass(GeneratorConfiguration $generatorConfiguration): string
124124
{
125-
$render = new Render(__DIR__ . '/../Templates/');
126125
$namespace = trim(join('\\', [$generatorConfiguration->getNamespacePrefix(), $this->classPath]), '\\');
127126

128-
$use = array_unique(
129-
array_merge(
130-
$this->schema->getUsedClasses(),
131-
$generatorConfiguration->collectErrors()
132-
? [$generatorConfiguration->getErrorRegistryClass()]
133-
: [ValidationException::class]
134-
)
135-
);
136-
137-
// filter out non-compound uses and uses which link to the current namespace
138-
$use = array_filter($use, function ($classPath) use ($namespace) {
139-
return strstr(trim(str_replace("$namespace", '', $classPath), '\\'), '\\') ||
140-
(!strstr($classPath, '\\') && !empty($namespace));
141-
});
142-
143127
try {
144-
$class = $render->renderTemplate(
128+
$class = (new Render(__DIR__ . '/../Templates/'))->renderTemplate(
145129
'Model.phptpl',
146130
[
147131
'namespace' => $namespace,
148-
'use' => $use,
132+
'use' => $this->getUseForSchema($generatorConfiguration, $namespace),
149133
'class' => $this->className,
150134
'schema' => $this->schema,
151135
'schemaHookResolver' => new SchemaHookResolver($this->schema),
@@ -167,4 +151,30 @@ function ($validator) {
167151

168152
return $class;
169153
}
170-
}
154+
155+
/**
156+
* @param GeneratorConfiguration $generatorConfiguration
157+
* @param string $namespace
158+
*
159+
* @return string[]
160+
*/
161+
protected function getUseForSchema(GeneratorConfiguration $generatorConfiguration, string $namespace): array
162+
{
163+
$use = array_unique(
164+
array_merge(
165+
$this->schema->getUsedClasses(),
166+
$generatorConfiguration->collectErrors()
167+
? [$generatorConfiguration->getErrorRegistryClass()]
168+
: [ValidationException::class]
169+
)
170+
);
171+
172+
// filter out non-compound uses and uses which link to the current namespace
173+
$use = array_filter($use, function ($classPath) use ($namespace) {
174+
return strstr(trim(str_replace("$namespace", '', $classPath), '\\'), '\\') ||
175+
(!strstr($classPath, '\\') && !empty($namespace));
176+
});
177+
178+
return $use;
179+
}
180+
}

0 commit comments

Comments
 (0)