Skip to content

Commit 89f6e1f

Browse files
committed
Move options to class property
1 parent 7f49c27 commit 89f6e1f

File tree

8 files changed

+22
-11
lines changed

8 files changed

+22
-11
lines changed

src/Commands/GenerateServer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function handleMapping(string $sourcePath, array $optionsPerEntity)
6666
}
6767

6868
$this->infoIfVerbose("Generating files for entity \"$entity\" using generator \"$generatorClass\"");
69-
resolve($generatorClass)->generate($specObject, $optionsPerEntity[$entity]);
69+
resolve($generatorClass)->setOptions($optionsPerEntity[$entity])->generate($specObject);
7070
}
7171

7272
return self::SUCCESS;

src/Generators/BaseGenerator.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
class BaseGenerator
1313
{
14+
protected array $options = [];
15+
1416
public function __construct(
1517
protected Filesystem $filesystem,
1618
protected TemplatesManager $templatesManager,
@@ -20,6 +22,13 @@ public function __construct(
2022
) {
2123
}
2224

25+
public function setOptions(array $options): static
26+
{
27+
$this->options = $options;
28+
29+
return $this;
30+
}
31+
2332
protected function replacePlaceholders(string $content, array $placeholders): string
2433
{
2534
return str_replace(array_keys($placeholders), array_values($placeholders), $content);

src/Generators/ControllersGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ControllersGenerator extends BaseGenerator implements GeneratorInterface
99
{
1010
private array $methodsWithRequests = ['PATCH', 'POST', 'PUT', 'DELETE'];
1111

12-
public function generate(SpecObjectInterface $specObject, array $options): void
12+
public function generate(SpecObjectInterface $specObject): void
1313
{
1414
$controllers = $this->extractControllers($specObject);
1515
$this->createControllersFiles($controllers, $this->templatesManager->getTemplate('Controller.template'));

src/Generators/EnumsGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
class EnumsGenerator extends BaseGenerator implements GeneratorInterface
1111
{
12-
public function generate(SpecObjectInterface $specObject, array $options): void
12+
public function generate(SpecObjectInterface $specObject): void
1313
{
14-
$namespaceData = $options['namespace'] ?? null;
14+
$namespaceData = $this->options['namespace'] ?? null;
1515
if (!is_string($namespaceData)) {
1616
throw new InvalidArgumentException("EnumsGenerator must be configured with string as 'namespace'");
1717
}

src/Generators/GeneratorInterface.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@
66

77
interface GeneratorInterface
88
{
9-
public function generate(SpecObjectInterface $specObject, array $options): void;
9+
public function generate(SpecObjectInterface $specObject): void;
10+
11+
public function setOptions(array $options): static;
1012
}

src/Generators/RequestsGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class RequestsGenerator extends BaseGenerator implements GeneratorInterface
99
{
1010
private array $methods = ['PATCH', 'POST', 'PUT', 'DELETE'];
1111

12-
public function generate(SpecObjectInterface $specObject, array $options): void
12+
public function generate(SpecObjectInterface $specObject): void
1313
{
14-
$namespaceData = $options['namespace'] ?? null;
14+
$namespaceData = $this->options['namespace'] ?? null;
1515
if (!is_array($namespaceData)) {
1616
throw new InvalidArgumentException("RequestsGenerator must be configured with array as 'namespace'");
1717
}

src/Generators/RoutesGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
class RoutesGenerator extends BaseGenerator implements GeneratorInterface
99
{
10-
public function generate(SpecObjectInterface $specObject, array $options): void
10+
public function generate(SpecObjectInterface $specObject): void
1111
{
12-
$namespaceData = $options['namespace'] ?? null;
12+
$namespaceData = $this->options['namespace'] ?? null;
1313
if (!is_string($namespaceData)) {
1414
throw new InvalidArgumentException("RoutesGenerator must be configured with string as 'namespace'");
1515
}

src/Generators/TestsGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ abstract protected function convertRoutesToImportsString(array $routes): string;
1414

1515
abstract protected function getTemplateName(): string;
1616

17-
public function generate(SpecObjectInterface $specObject, array $options): void
17+
public function generate(SpecObjectInterface $specObject): void
1818
{
19-
$namespaceData = $options['namespace'] ?? null;
19+
$namespaceData = $this->options['namespace'] ?? null;
2020
if (!is_array($namespaceData)) {
2121
throw new InvalidArgumentException("TestsGenerator must be configured with array as 'namespace'");
2222
}

0 commit comments

Comments
 (0)