Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
/// <inheritdoc />
public async Task RemoveConnectionStringAsync()
{
JsonConfigurationProvider? provider = GetJsonConfigurationProvider(UmbracoConnectionStringPath);
// attempt to get the Development configuration, fallback to default
JsonConfigurationProvider? provider = GetJsonConfigurationProvider("Development", UmbracoConnectionStringPath) ?? GetJsonConfigurationProvider(requiredKey: UmbracoConnectionStringPath);

JsonNode? jsonNode = await GetJsonNodeAsync(provider);

Expand All @@ -52,7 +53,9 @@
/// <inheritdoc />
public async Task SaveConnectionStringAsync(string connectionString, string? providerName)
{
JsonConfigurationProvider? provider = GetJsonConfigurationProvider();
// attempt to get the Development configuration, fallback to default
JsonConfigurationProvider? provider = GetJsonConfigurationProvider("Development") ?? GetJsonConfigurationProvider();

JsonNode? node = await GetJsonNodeAsync(provider);

if (node is null)
Expand Down Expand Up @@ -237,7 +240,7 @@
}
}

private JsonConfigurationProvider? GetJsonConfigurationProvider(string? requiredKey = null)
private JsonConfigurationProvider? GetJsonConfigurationProvider(string? environment = null, string? requiredKey = null)
{
if (_configuration is not IConfigurationRoot configurationRoot)
{
Expand All @@ -247,6 +250,7 @@
foreach (IConfigurationProvider provider in configurationRoot.Providers)
{
if (provider is JsonConfigurationProvider jsonConfigurationProvider &&
(environment is null || provider.Source.Path.EndsWith($"appsettings.{environment}.json")) &&

Check warning on line 253 in src/Umbraco.Infrastructure/Configuration/JsonConfigManipulator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

❌ Getting worse: Complex Conditional

GetJsonConfigurationProvider increases from 1 complex conditionals with 2 branches to 1 complex conditionals with 4 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
(requiredKey is null || provider.TryGet(requiredKey, out _)))
{
return jsonConfigurationProvider;
Expand Down
Loading