Skip to content

Commit d281f34

Browse files
author
Adil Ausagit
committed
#32 changed logic to arr::dot()
1 parent 7a180a5 commit d281f34

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/Commands/MakeEntityCommand.php

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -181,37 +181,29 @@ protected function checkConfigs()
181181

182182
$projectConfigs = config('entity-generator');
183183

184-
$newConfig = array_replace_recursive($packageConfigs, $projectConfigs);
185-
186-
$this->outputInfo($newConfig, $projectConfigs);
184+
$newConfig = $this->outputNewConfig($packageConfigs, $projectConfigs);
187185

188186
if ($newConfig !== $projectConfigs) {
189-
$this->info("Config has been updated");
187+
$this->info('Config has been updated');
190188
Config::set('entity-generator', $newConfig);
191189
file_put_contents(config_path('entity-generator.php'), "<?php\n\nreturn" . $this->customVarExport($newConfig) . ';');
192190
}
193191
}
194192

195-
protected function outputInfo($newProjectConfigs, $oldProjectConfigs)
193+
protected function outputNewConfig($packageConfigs, $projectConfigs)
196194
{
197-
$newProjectConfigsFullDepth = [];
198-
$oldProjectConfigsFullDepth = [];
199-
200-
array_walk_recursive($newProjectConfigs, function ($value, $key) use (&$newProjectConfigsFullDepth) {
201-
$newProjectConfigsFullDepth[$value] = $key;
202-
});
195+
$flattenedPackageConfigs = Arr::dot($packageConfigs);
196+
$flattenedProjectConfigs = Arr::dot($projectConfigs);
203197

204-
array_walk_recursive($oldProjectConfigs, function ($value, $key) use (&$oldProjectConfigsFullDepth) {
205-
$oldProjectConfigsFullDepth[$value] = $key;
206-
});
198+
$newConfig = array_merge($flattenedPackageConfigs, $flattenedProjectConfigs);
207199

208-
$differences = array_diff_key($newProjectConfigsFullDepth, $oldProjectConfigsFullDepth);
200+
$differences = array_diff_key($newConfig, $flattenedProjectConfigs);
209201

210-
if (!empty($differences)) {
211-
foreach ($differences as $differenceKey => $differenceValue) {
212-
$this->info("Key '{$differenceValue}' was missing in your config, we added it with the value '{$differenceKey}'");
213-
}
202+
foreach ($differences as $differenceKey => $differenceValue) {
203+
$this->info("Key '{$differenceKey}' was missing in your config, we added it with the value '{$differenceValue}'");
214204
}
205+
206+
return array_undot($newConfig);
215207
}
216208

217209
protected function customVarExport($expression)

0 commit comments

Comments
 (0)