/**
* Rename the given oldKey to the newKey.
*
* @return void
*/
private function renameKey()
{
try {
list($file, $key) = explode('.', $this->argument('oldKey'), 2);
} catch (\ErrorException $e) {
$this->error('Could not recognize the key you want to rename.');
return;
}
if (Str::contains($this->argument('newKey'), '.')) {
$this->error('Please provide the new key must not contain a dot.');
return;
}
$newKey = preg_replace('/(\\w+)$/i', $this->argument('newKey'), $key);
$files = $this->manager->files()[$file];
$currentValues = [];
foreach ($files as $languageKey => $filePath) {
$content = Arr::dot($this->manager->getFileContent($filePath));
$currentValues[$languageKey] = isset($content[$key]) ? $content[$key] : '';
}
$this->manager->removeKey($file, $key);
$this->manager->fillKeys($file, [$newKey => $currentValues]);
}