refactor: Fix various analysis issues

pull/201/head
Robert Dailey 1 year ago
parent 5d0db006ba
commit 7185cc5844

@ -7,9 +7,9 @@ internal class DefaultEnvironment : IEnvironment
return Environment.GetFolderPath(folder);
}
public string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option)
public string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption folderOption)
{
return Environment.GetFolderPath(folder, option);
return Environment.GetFolderPath(folder, folderOption);
}
public string? GetEnvironmentVariable(string variable)

@ -3,6 +3,6 @@
public interface IEnvironment
{
public string GetFolderPath(Environment.SpecialFolder folder);
string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option);
string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption folderOption);
string? GetEnvironmentVariable(string variable);
}

@ -33,7 +33,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.Get<SonarrConfiguration>(SupportedServices.Sonarr);
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[]
{
new
@ -58,7 +58,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.Get<SonarrConfiguration>(SupportedServices.Sonarr);
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[]
{
new
@ -85,7 +85,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.Get<SonarrConfiguration>(SupportedServices.Sonarr);
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[]
{
new
@ -112,7 +112,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.Get<SonarrConfiguration>(SupportedServices.Sonarr);
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[]
{
new
@ -137,7 +137,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.Get<SonarrConfiguration>(SupportedServices.Sonarr);
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[]
{
new
@ -161,7 +161,7 @@ sonarr:
var configCollection = sut.LoadFromStream(new StringReader(testYml));
var config = configCollection.Get<SonarrConfiguration>(SupportedServices.Sonarr);
var config = configCollection.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr);
config.Should().BeEquivalentTo(new[]
{
new

@ -55,7 +55,7 @@ secret_rp: 1234567
};
var parsedSecret = configLoader.LoadFromStream(new StringReader(testYml), "sonarr");
parsedSecret.Get<SonarrConfiguration>(SupportedServices.Sonarr)
parsedSecret.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr)
.Should().BeEquivalentTo(expected, o => o.Excluding(x => x.LineNumber));
}

@ -81,10 +81,10 @@ public class ConfigurationLoaderTest : IntegrationFixture
var loader = Resolve<IConfigurationLoader>();
var actual = loader.LoadMany(fileData.Select(x => x.Item1));
actual.Get<SonarrConfiguration>(SupportedServices.Sonarr)
actual.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr)
.Should().BeEquivalentTo(expectedSonarr);
actual.Get<RadarrConfiguration>(SupportedServices.Radarr)
actual.GetConfigsOfType<RadarrConfiguration>(SupportedServices.Radarr)
.Should().BeEquivalentTo(expectedRadarr);
}
@ -94,7 +94,7 @@ public class ConfigurationLoaderTest : IntegrationFixture
var configLoader = Resolve<ConfigurationLoader>();
var configs = configLoader.LoadFromStream(GetResourceData("Load_UsingStream_CorrectParsing.yml"), "sonarr");
configs.Get<SonarrConfiguration>(SupportedServices.Sonarr)
configs.GetConfigsOfType<SonarrConfiguration>(SupportedServices.Sonarr)
.Should().BeEquivalentTo(new List<SonarrConfiguration>
{
new()

@ -14,7 +14,7 @@ public class ConfigParser
{
private readonly ConfigValidationExecutor _validator;
private readonly IDeserializer _deserializer;
private readonly ConfigCollection _configs = new();
private readonly ConfigRegistry _configs = new();
private SupportedServices? _currentSection;
private readonly Dictionary<SupportedServices, Type> _configTypes = new()
@ -23,7 +23,7 @@ public class ConfigParser
{SupportedServices.Radarr, typeof(RadarrConfiguration)}
};
public IConfigCollection Configs => _configs;
public IConfigRegistry Configs => _configs;
public ConfigParser(
IYamlSerializerFactory yamlFactory,

@ -3,7 +3,7 @@ using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.Config.Parsing;
public class ConfigCollection : IConfigCollection
public class ConfigRegistry : IConfigRegistry
{
private readonly Dictionary<SupportedServices, List<ServiceConfiguration>> _configs = new();
@ -12,7 +12,7 @@ public class ConfigCollection : IConfigCollection
_configs.GetOrCreate(configType).Add(config);
}
public IReadOnlyCollection<T> Get<T>(SupportedServices serviceType) where T : ServiceConfiguration
public IReadOnlyCollection<T> GetConfigsOfType<T>(SupportedServices serviceType) where T : ServiceConfiguration
{
return _configs[serviceType].Cast<T>().ToList();
}

@ -18,7 +18,7 @@ public class ConfigurationLoader : IConfigurationLoader
_parser = parser;
}
public IConfigCollection LoadMany(IEnumerable<IFileInfo> configFiles, string? desiredSection = null)
public IConfigRegistry LoadMany(IEnumerable<IFileInfo> configFiles, string? desiredSection = null)
{
foreach (var file in configFiles)
{
@ -28,7 +28,7 @@ public class ConfigurationLoader : IConfigurationLoader
return _parser.Configs;
}
public IConfigCollection Load(IFileInfo file, string? desiredSection = null)
public IConfigRegistry Load(IFileInfo file, string? desiredSection = null)
{
_log.Debug("Loading config file: {File}", file);
using var logScope = LogContext.PushProperty(LogProperty.Scope, file.Name);
@ -63,7 +63,7 @@ public class ConfigurationLoader : IConfigurationLoader
return _parser.Configs;
}
public IConfigCollection LoadFromStream(TextReader stream, string? desiredSection = null)
public IConfigRegistry LoadFromStream(TextReader stream, string? desiredSection = null)
{
var parser = new Parser(stream);

@ -1,9 +0,0 @@
using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.Config.Parsing;
public interface IConfigCollection
{
IReadOnlyCollection<T> Get<T>(SupportedServices serviceType) where T : ServiceConfiguration;
bool DoesConfigExist(string name);
}

@ -0,0 +1,9 @@
using Recyclarr.TrashLib.Config.Services;
namespace Recyclarr.TrashLib.Config.Parsing;
public interface IConfigRegistry
{
IReadOnlyCollection<T> GetConfigsOfType<T>(SupportedServices serviceType) where T : ServiceConfiguration;
bool DoesConfigExist(string name);
}

@ -4,7 +4,7 @@ namespace Recyclarr.TrashLib.Config.Parsing;
public interface IConfigurationLoader
{
IConfigCollection LoadMany(IEnumerable<IFileInfo> configFiles, string? desiredSection = null);
IConfigCollection Load(IFileInfo file, string? desiredSection = null);
IConfigCollection LoadFromStream(TextReader stream, string? desiredSection = null);
IConfigRegistry LoadMany(IEnumerable<IFileInfo> configFiles, string? desiredSection = null);
IConfigRegistry Load(IFileInfo file, string? desiredSection = null);
IConfigRegistry LoadFromStream(TextReader stream, string? desiredSection = null);
}

@ -1,10 +1,18 @@
using System.Diagnostics.CodeAnalysis;
namespace Recyclarr.TrashLib.Config.Services;
public interface IServiceConfiguration
{
string ServiceName { get; }
string? InstanceName { get; }
[SuppressMessage("Design", "CA1056:URI-like properties should not be strings",
Justification = "This is not treated as a true URI until later")]
string BaseUrl { get; }
string ApiKey { get; }
bool DeleteOldCustomFormats { get; }
}

@ -71,10 +71,10 @@ public class SyncProcessor : ISyncProcessor
}
private async Task<bool> ProcessService<TConfig>(
SupportedServices service, ISyncSettings settings, IConfigCollection configs)
SupportedServices service, ISyncSettings settings, IConfigRegistry configs)
where TConfig : ServiceConfiguration
{
var serviceConfigs = configs.Get<TConfig>(service);
var serviceConfigs = configs.GetConfigsOfType<TConfig>(service);
// If any config names are null, that means user specified array-style (deprecated) instances.
if (serviceConfigs.Any(x => x.InstanceName is null))

Loading…
Cancel
Save