From 7343616a47cd538bba4c9128d2c1094561f9b3a5 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 26 May 2023 18:32:35 +0300 Subject: [PATCH] Simplify ShouldHaveApiKey and HasErrors --- .../Indexers/Newznab/NewznabSettings.cs | 7 +------ .../Indexers/Torznab/TorznabSettings.cs | 7 +------ .../Validation/NzbDroneValidationExtensions.cs | 12 +----------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs index f5ccae45d..688be0d1f 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabSettings.cs @@ -23,12 +23,7 @@ namespace NzbDrone.Core.Indexers.Newznab private static bool ShouldHaveApiKey(NewznabSettings settings) { - if (settings.BaseUrl == null) - { - return false; - } - - return ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c)); + return settings.BaseUrl != null && ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c)); } private static readonly Regex AdditionalParametersRegex = new Regex(@"(&.+?\=.+?)+", RegexOptions.Compiled); diff --git a/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs b/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs index 1c9901a8f..ff5f59f65 100644 --- a/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Torznab/TorznabSettings.cs @@ -17,12 +17,7 @@ namespace NzbDrone.Core.Indexers.Torznab private static bool ShouldHaveApiKey(TorznabSettings settings) { - if (settings.BaseUrl == null) - { - return false; - } - - return ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c)); + return settings.BaseUrl != null && ApiKeyWhiteList.Any(c => settings.BaseUrl.ToLowerInvariant().Contains(c)); } private static readonly Regex AdditionalParametersRegex = new Regex(@"(&.+?\=.+?)+", RegexOptions.Compiled); diff --git a/src/NzbDrone.Core/Validation/NzbDroneValidationExtensions.cs b/src/NzbDrone.Core/Validation/NzbDroneValidationExtensions.cs index f299c8ac3..46a247873 100644 --- a/src/NzbDrone.Core/Validation/NzbDroneValidationExtensions.cs +++ b/src/NzbDrone.Core/Validation/NzbDroneValidationExtensions.cs @@ -24,17 +24,7 @@ namespace NzbDrone.Core.Validation public static bool HasErrors(this List list) { - foreach (var item in list) - { - if (item is NzbDroneValidationFailure { IsWarning: true }) - { - continue; - } - - return true; - } - - return false; + return list.Any(item => item is not NzbDroneValidationFailure { IsWarning: true }); } } }