Skip to content

Commit

Permalink
Move method up to where it’s called.
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseleite committed Aug 13, 2024
1 parent b91fd06 commit 814de4c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
36 changes: 18 additions & 18 deletions src/StarterKits/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ protected function instantiateModules(): self
return $this;
}

/**
* Instantiate module and check if nested modules should be recursively instantiated.
*/
protected function instantiateModuleRecursively(array $config, string $key): ExportableModule|array
{
$instantiated = new ExportableModule($config, $key);

if ($modules = Arr::get($config, 'modules')) {
$instantiated = collect($modules)
->map(fn ($config, $childKey) => $this->instantiateModule($config, $this->normalizeModuleKey($key, $childKey)))
->prepend($instantiated, $key)
->filter()
->all();
}

return $instantiated;
}

/**
* Instantiate individual module.
*/
Expand All @@ -106,24 +124,6 @@ protected function instantiateSelectModule(array $config, string $key): Exportab
->all();
}

/**
* Instantiate module and check if nested modules should be recursively instantiated.
*/
protected function instantiateModuleRecursively(array $config, string $key): ExportableModule|array
{
$instantiated = new ExportableModule($config, $key);

if ($modules = Arr::get($config, 'modules')) {
$instantiated = collect($modules)
->map(fn ($config, $childKey) => $this->instantiateModule($config, $this->normalizeModuleKey($key, $childKey)))
->prepend($instantiated, $key)
->filter()
->all();
}

return $instantiated;
}

/**
* Normalize module key, as dotted array key for location in starter-kit.yaml.
*/
Expand Down
36 changes: 18 additions & 18 deletions src/StarterKits/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,24 @@ protected function instantiateModules(): self
return $this;
}

/**
* Instantiate module and check if nested modules should be recursively instantiated.
*/
protected function instantiateModuleRecursively(array $config, string $key): InstallableModule|array
{
$instantiated = (new InstallableModule($config, $key))->installer($this);

if ($modules = Arr::get($config, 'modules')) {
$instantiated = collect($modules)
->map(fn ($config, $childKey) => $this->instantiateModule($config, $this->normalizeModuleKey($key, $childKey)))
->prepend($instantiated, $key)
->filter()
->all();
}

return $instantiated;
}

/**
* Instantiate individual module.
*/
Expand Down Expand Up @@ -352,24 +370,6 @@ protected function instantiateSelectModule(array $config, string $key): Installa
return $this->instantiateModuleRecursively($selectedModuleConfig, $selectedKey);
}

/**
* Instantiate module and check if nested modules should be recursively instantiated.
*/
protected function instantiateModuleRecursively(array $config, string $key): InstallableModule|array
{
$instantiated = (new InstallableModule($config, $key))->installer($this);

if ($modules = Arr::get($config, 'modules')) {
$instantiated = collect($modules)
->map(fn ($config, $childKey) => $this->instantiateModule($config, $this->normalizeModuleKey($key, $childKey)))
->prepend($instantiated, $key)
->filter()
->all();
}

return $instantiated;
}

/**
* Normalize module key.
*/
Expand Down

0 comments on commit 814de4c

Please sign in to comment.