refactor: Reduce cognitive complexity of method

pull/201/head
Robert Dailey 1 year ago
parent 134477ab46
commit 3c5b139523

@ -67,7 +67,6 @@ public class CustomFormatSyncPipeline : ISyncPipeline
return;
}
// todo: Update the ProcessedCustomFormat objects' FormatId after API calls
await _phases.ApiPersistencePhase.Execute(config, transactions);
_cachePersister.Save(config, cache.Update(guideCfs));

@ -34,37 +34,7 @@ public class CustomFormatTransactionPhase
var serviceCf = FindServiceCfByName(serviceData, guideCf.Name);
if (serviceCf is not null)
{
if (config.ReplaceExistingCustomFormats)
{
// replace:
// - Use the ID from the service, not the cache, and do an update
if (guideCf.Id != serviceCf.Id)
{
_log.Debug(
"Format IDs for CF {Name} did not match which indicates a manually-created CF is " +
"replaced, or that the cache is out of sync with the service ({GuideId} != {ServiceId})",
serviceCf.Name, guideCf.Id, serviceCf.Id);
guideCf.Id = serviceCf.Id;
}
AddUpdatedCustomFormat(guideCf, serviceCf, transactions);
}
else
{
// NO replace:
// - ids must match (can't rename another cf to the same name), otherwise error
if (guideCf.Id != serviceCf.Id)
{
transactions.ConflictingCustomFormats.Add(
new ConflictingCustomFormat(guideCf, serviceCf.Id));
}
else
{
AddUpdatedCustomFormat(guideCf, serviceCf, transactions);
}
}
ProcessExistingCf(config, guideCf, serviceCf, transactions);
continue;
}
@ -91,6 +61,44 @@ public class CustomFormatTransactionPhase
return transactions;
}
private void ProcessExistingCf(
IServiceConfiguration config,
CustomFormatData guideCf,
CustomFormatData serviceCf,
CustomFormatTransactionData transactions)
{
if (config.ReplaceExistingCustomFormats)
{
// replace:
// - Use the ID from the service, not the cache, and do an update
if (guideCf.Id != serviceCf.Id)
{
_log.Debug(
"Format IDs for CF {Name} did not match which indicates a manually-created CF is " +
"replaced, or that the cache is out of sync with the service ({GuideId} != {ServiceId})",
serviceCf.Name, guideCf.Id, serviceCf.Id);
guideCf.Id = serviceCf.Id;
}
AddUpdatedCustomFormat(guideCf, serviceCf, transactions);
}
else
{
// NO replace:
// - ids must match (can't rename another cf to the same name), otherwise error
if (guideCf.Id != serviceCf.Id)
{
transactions.ConflictingCustomFormats.Add(
new ConflictingCustomFormat(guideCf, serviceCf.Id));
}
else
{
AddUpdatedCustomFormat(guideCf, serviceCf, transactions);
}
}
}
private static void AddUpdatedCustomFormat(
CustomFormatData guideCf,
CustomFormatData serviceCf,

Loading…
Cancel
Save