Skip to content

Commit 412f7e9

Browse files
committed
More generic Generator
1 parent 0471269 commit 412f7e9

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Tool/Generator.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,17 @@ private function writeClass(string $namespacedClass, string $apiPath, array $pro
267267
$parameters = [];
268268
$docblock = '';
269269

270-
foreach ($specs['parameters'] as $parameter)
270+
foreach ($specs['parameters'] ?? [] as $parameter)
271271
{
272272
if (isset($parameter['schema']))
273273
{
274274
$type = $this->getTypeNameFromRef($parameter['schema']['$ref']);
275275
}
276276
else
277277
{
278-
$type = $this->getPHPType($parameter['type']);
278+
$type = $this->getPHPType($parameter['type'] ?? '');
279279
}
280-
$name = \str_replace(' ', '_', $parameter['name']);
280+
$name = \str_replace(' ', '_', $parameter['name'] ?? '');
281281

282282
if (isset($parameter['enum']))
283283
{
@@ -289,11 +289,13 @@ private function writeClass(string $namespacedClass, string $apiPath, array $pro
289289
$csv[$name] = true;
290290
}
291291

292-
$docblock .= "\n\t * @param {$type} {$dollar}{$name} {$parameter['description']}";
293-
$parameterString = $parameter['required'] ? '' : '?';
292+
$description = $parameter['description'] ?? '';
293+
$docblock .= "\n\t * @param {$type} {$dollar}{$name} {$description}";
294+
$required = $parameter['required'] ?? false;
295+
$parameterString = $required ? '' : '?';
294296
$parameterString .= $type . ' $' . $name;
295297

296-
if (! $parameter['required'])
298+
if (! $required)
297299
{
298300
$parameterString .= ' = null';
299301
}
@@ -611,6 +613,10 @@ private function deleteFileTree(string $path) : void
611613
{
612614
$directory = __DIR__ . '/../src/ConstantContact' . $path;
613615

616+
if (! is_dir($directory))
617+
{
618+
mkdir($directory, 0x077, true);
619+
}
614620
$iterator = new \RecursiveIteratorIterator(
615621
new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS),
616622
\RecursiveIteratorIterator::SELF_FIRST

0 commit comments

Comments
 (0)