Skip to content

Commit 13c96a3

Browse files
committed
Dashes in class names are a no-go
1 parent a1815c9 commit 13c96a3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Generator.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function generate(string $namespace, string $destinationPath)
2525
$codePrinter = new Standard();
2626
$schemaClassNameMap = [];
2727
foreach ($this->spec->components->schemas as $name => $schema) {
28-
$schemaClassName = trim(str_replace(['{', '}'], ['Cb', 'Rcb'], (new Convert($name))->toPascal()));
28+
$schemaClassName = $this->className($name);
2929
if (strlen($schemaClassName) === 0) {
3030
continue;
3131
}
@@ -46,7 +46,7 @@ public function generate(string $namespace, string $destinationPath)
4646
}
4747

4848
foreach ($this->spec->paths as $path => $pathItem) {
49-
$pathClassName = str_replace(['{', '}'], ['Cb', 'Rcb'], (new Convert($path))->toPascal());
49+
$pathClassName = $this->className($path);
5050
@mkdir(dirname($destinationPath . '/Path/' . $pathClassName), 0777, true);
5151
file_put_contents($destinationPath . '/Path/' . $pathClassName . '.php', $codePrinter->prettyPrintFile([
5252
Path::generate(
@@ -58,7 +58,7 @@ public function generate(string $namespace, string $destinationPath)
5858
),
5959
]) . PHP_EOL);
6060
foreach ($pathItem->getOperations() as $method => $operation) {
61-
$operationClassName = (new Convert($operation->operationId))->fromTrain()->toPascal();
61+
$operationClassName = $this->className((new Convert($operation->operationId))->fromTrain()->toPascal());
6262
$operations[$method] = $operationClassName;
6363

6464
@mkdir(dirname($destinationPath . '/Operation/' . $operationClassName), 0777, true);
@@ -75,4 +75,9 @@ public function generate(string $namespace, string $destinationPath)
7575
}
7676

7777
}
78+
79+
private function className(string $className): string
80+
{
81+
return str_replace(['{', '}', '-'], ['Cb', 'Rcb', 'Dash'], (new Convert($className))->toPascal());
82+
}
7883
}

0 commit comments

Comments
 (0)