Skip to content

Commit 63c2999

Browse files
committed
Pass to generators
1 parent 9f3b63b commit 63c2999

File tree

99 files changed

+258
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+258
-261
lines changed

src/Command/Composer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ final class Composer extends DrupalGenerator {
1919
/**
2020
* {@inheritdoc}
2121
*/
22-
protected function generate(): void {
23-
$vars = &$this->collectDefault();
22+
protected function generate(array &$vars): void {
23+
$this->collectDefault($vars);
2424
$vars['description'] = $this->ask('Description');
2525

2626
$type_question = new Question('Type', 'drupal-module');

src/Command/ConfigurationEntity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ final class ConfigurationEntity extends ModuleGenerator {
1414
/**
1515
* {@inheritdoc}
1616
*/
17-
protected function generate(): void {
18-
$vars = &$this->collectDefault();
17+
protected function generate(array &$vars): void {
18+
$this->collectDefault($vars);
1919

2020
$vars['entity_type_label'] = $this->ask('Entity type label', '{name}');
2121
$vars['entity_type_id'] = $this->ask('Entity type ID', '{entity_type_label|h2m}');

src/Command/Console/DcgCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ final class DcgCommand extends Generator {
1818
/**
1919
* {@inheritdoc}
2020
*/
21-
protected function generate(): void {
22-
$vars = &$this->vars;
23-
21+
protected function generate(array &$vars): void {
2422
$command_name_validator = static function (?string $value): ?string {
2523
return self::validate($value, '^[a-z][a-z0-9-_:]*[a-z0-9]$', 'The value is not correct command name.');
2624
};

src/Command/Console/DrupalConsoleCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ final class DrupalConsoleCommand extends ModuleGenerator {
1616
/**
1717
* {@inheritdoc}
1818
*/
19-
protected function generate(): void {
20-
$vars = &$this->collectDefault();
19+
protected function generate(array &$vars): void {
20+
$this->collectDefault($vars);
2121

2222
$vars['command_name'] = $this->ask('Command name', '{machine_name}:example');
2323
$vars['description'] = $this->ask('Command description', 'Command description.');

src/Command/Console/DrushCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ final class DrushCommand extends Generator {
1616
/**
1717
* {@inheritdoc}
1818
*/
19-
protected function generate(): void {
20-
$vars = &$this->vars;
21-
19+
protected function generate(array &$vars): void {
2220
$vars['command_name'] = $this->ask('Command name', '');
2321
$vars['alias'] = $this->ask('Command alias', \substr($vars['command_name'], 0, 3));
2422
$vars['description'] = $this->ask('Command description', 'Command description.');

src/Command/Console/SymfonyCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ final class SymfonyCommand extends ModuleGenerator {
1717
/**
1818
* {@inheritdoc}
1919
*/
20-
protected function generate(): void {
21-
$vars = &$this->collectDefault();
20+
protected function generate(array &$vars): void {
21+
$this->collectDefault($vars);
2222
$command_name_validator = static function (?string $value): ?string {
2323
return self::validate($value, '^[a-z][a-z0-9-_:]*[a-z0-9]$', 'The value is not correct command name.');
2424
};

src/Command/ContentEntity.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ final class ContentEntity extends ModuleGenerator {
1313
/**
1414
* {@inheritdoc}
1515
*/
16-
protected function generate(): void {
17-
$vars = &$this->collectDefault();
16+
protected function generate(array &$vars): void {
17+
$this->collectDefault($vars);
1818

1919
$vars['entity_type_label'] = $this->ask('Entity type label', '{name}');
2020
$vars['entity_type_id'] = $this->ask('Entity type ID', '{entity_type_label|h2m}');

src/Command/Controller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ final class Controller extends ModuleGenerator {
1313
/**
1414
* {@inheritdoc}
1515
*/
16-
protected function generate(): void {
17-
$vars = &$this->collectDefault();
16+
protected function generate(array &$vars): void {
17+
$this->collectDefault($vars);
1818
$vars['class'] = $this->ask('Class', '{machine_name|camelize}Controller');
1919

20-
$this->collectServices(FALSE);
20+
$this->collectServices($vars, FALSE);
2121

2222
if ($this->confirm('Would you like to create a route for this controller?')) {
2323
$vars['route_name'] = $this->ask('Route name', '{machine_name}.example');

src/Command/DrupalGenerator.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,22 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
7979
/**
8080
* Collects default variables.
8181
*/
82-
protected function &collectDefault(): array {
82+
protected function collectDefault(array &$vars): void {
8383
// If both name and machine_name questions are defined it is quite possible
8484
// that we can provide the extension name without interacting with a user.
8585
if (!$this->isNewExtension && $this->drupalContext && $this->nameQuestion && $this->machineNameQuestion) {
8686
$extensions = $this->getExtensionList();
87-
$this->vars['machine_name'] = $this->askMachineNameQuestion();
88-
$this->vars['name'] = $extensions[$this->vars['machine_name']] ?? Utils::machine2human($this->vars['machine_name']);
87+
$vars['machine_name'] = $this->askMachineNameQuestion($vars);
88+
$vars['name'] = $extensions[$vars['machine_name']] ?? Utils::machine2human($vars['machine_name']);
8989
}
9090
else {
9191
if ($this->nameQuestion) {
92-
$this->vars['name'] = $this->askNameQuestion();
92+
$vars['name'] = $this->askNameQuestion();
9393
}
9494
if ($this->machineNameQuestion) {
95-
$this->vars['machine_name'] = $this->askMachineNameQuestion();
95+
$vars['machine_name'] = $this->askMachineNameQuestion($vars);
9696
}
9797
}
98-
return $this->vars;
9998
}
10099

101100
/**
@@ -115,8 +114,8 @@ protected function askNameQuestion(): string {
115114
/**
116115
* Asks machine name question.
117116
*/
118-
protected function askMachineNameQuestion(): string {
119-
$default_value = Utils::human2machine($this->vars['name'] ?? \basename($this->directory));
117+
protected function askMachineNameQuestion(array $vars): string {
118+
$default_value = Utils::human2machine($vars['name'] ?? \basename($this->directory));
120119
$machine_name_question = new Question($this->machineNameQuestion, $default_value);
121120
$machine_name_question->setValidator([static::class, 'validateRequiredMachineName']);
122121
if (!$this->isNewExtension && $extensions = $this->getExtensionList()) {
@@ -139,15 +138,15 @@ protected function getExtensionList(): array {
139138
/**
140139
* {@inheritdoc}
141140
*/
142-
protected function getDestination(): ?string {
141+
protected function getDestination(array $vars): ?string {
143142
if ($this->drupalContext && $this->extensionType) {
144143
$destination = $this->drupalContext->getDestination(
145144
$this->extensionType,
146145
$this->isNewExtension,
147-
$this->vars['machine_name'] ?? NULL,
146+
$vars['machine_name'] ?? NULL,
148147
);
149148
}
150-
return $destination ?? parent::getDestination();
149+
return $destination ?? parent::getDestination($vars);
151150
}
152151

153152
}

src/Command/Field.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ final class Field extends ModuleGenerator {
113113
/**
114114
* {@inheritdoc}
115115
*/
116-
protected function generate(): void {
116+
protected function generate(array &$vars): void {
117117

118-
$vars = &$this->collectDefault();
118+
$this->collectDefault($vars);
119119

120120
$vars['field_label'] = $this->ask('Field label', 'Example', '::validateRequired');
121121
$vars['field_id'] = $this->ask('Field ID', '{machine_name}_{field_label|h2m}', '::validateRequiredMachineName');

0 commit comments

Comments
 (0)