From fcfec1b8591ec7c9cfed7df804b3136ff0bb6da8 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Fri, 26 May 2023 18:32:35 +0300 Subject: [PATCH] Simplify ShouldHaveApiKey and HasErrors (cherry picked from commit 7343616a47cd538bba4c9128d2c1094561f9b3a5) --- .../Indexers/Definitions/Newznab/NewznabSettings.cs | 7 +------ .../Indexers/Definitions/Torznab/TorznabSettings.cs | 7 +------ .../Validation/NzbDroneValidationExtensions.cs | 12 +----------- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs index 6551b2b30..5717d978b 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Newznab/NewznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/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/Definitions/Torznab/TorznabSettings.cs b/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs index 4374c1256..31b4cac17 100644 --- a/src/NzbDrone.Core/Indexers/Definitions/Torznab/TorznabSettings.cs +++ b/src/NzbDrone.Core/Indexers/Definitions/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 }); } } }