From 87c7eec8529caca9129e6df8674200d2745040a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Sun, 5 Jul 2020 16:11:12 +0200 Subject: [PATCH] Change the action level of the CA1725 rule and update affected methods --- eng/CodeAnalysis.ruleset | 2 +- .../Helpers/FormValueRequiredAttribute.cs | 16 +++++----- .../Primitives/OpenIddictConverter.cs | 30 +++++++++---------- .../Primitives/OpenIddictParameter.cs | 11 ++++--- ...OpenIddictEntityFrameworkCoreCustomizer.cs | 10 +++---- .../Primitives/OpenIddictConverterTests.cs | 10 +++---- 6 files changed, 39 insertions(+), 40 deletions(-) diff --git a/eng/CodeAnalysis.ruleset b/eng/CodeAnalysis.ruleset index 443912d2..3df93190 100644 --- a/eng/CodeAnalysis.ruleset +++ b/eng/CodeAnalysis.ruleset @@ -69,7 +69,7 @@ - + diff --git a/samples/Mvc.Server/Helpers/FormValueRequiredAttribute.cs b/samples/Mvc.Server/Helpers/FormValueRequiredAttribute.cs index f97cfee5..56183d1c 100644 --- a/samples/Mvc.Server/Helpers/FormValueRequiredAttribute.cs +++ b/samples/Mvc.Server/Helpers/FormValueRequiredAttribute.cs @@ -14,27 +14,27 @@ namespace Mvc.Server.Helpers _name = name; } - public override bool IsValidForRequest(RouteContext context, ActionDescriptor action) + public override bool IsValidForRequest(RouteContext routeContext, ActionDescriptor action) { - if (string.Equals(context.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) || - string.Equals(context.HttpContext.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) || - string.Equals(context.HttpContext.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) || - string.Equals(context.HttpContext.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(routeContext.HttpContext.Request.Method, "GET", StringComparison.OrdinalIgnoreCase) || + string.Equals(routeContext.HttpContext.Request.Method, "HEAD", StringComparison.OrdinalIgnoreCase) || + string.Equals(routeContext.HttpContext.Request.Method, "DELETE", StringComparison.OrdinalIgnoreCase) || + string.Equals(routeContext.HttpContext.Request.Method, "TRACE", StringComparison.OrdinalIgnoreCase)) { return false; } - if (string.IsNullOrEmpty(context.HttpContext.Request.ContentType)) + if (string.IsNullOrEmpty(routeContext.HttpContext.Request.ContentType)) { return false; } - if (!context.HttpContext.Request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase)) + if (!routeContext.HttpContext.Request.ContentType.StartsWith("application/x-www-form-urlencoded", StringComparison.OrdinalIgnoreCase)) { return false; } - return !string.IsNullOrEmpty(context.HttpContext.Request.Form[_name]); + return !string.IsNullOrEmpty(routeContext.HttpContext.Request.Form[_name]); } } } diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs index 13c7af4c..132b63e0 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictConverter.cs @@ -19,40 +19,40 @@ namespace OpenIddict.Abstractions /// /// Determines whether the specified type is supported by this converter. /// - /// The type to convert. + /// The type to convert. /// true if the type is supported, false otherwise. - public override bool CanConvert([NotNull] Type type) + public override bool CanConvert([NotNull] Type typeToConvert) { - if (type == null) + if (typeToConvert == null) { - throw new ArgumentNullException(nameof(type)); + throw new ArgumentNullException(nameof(typeToConvert)); } - return type == typeof(OpenIddictMessage) || - type == typeof(OpenIddictRequest) || - type == typeof(OpenIddictResponse); + return typeToConvert == typeof(OpenIddictMessage) || + typeToConvert == typeof(OpenIddictRequest) || + typeToConvert == typeof(OpenIddictResponse); } /// /// Deserializes an instance. /// /// The JSON reader. - /// The type of the deserialized instance. + /// The type of the deserialized instance. /// The JSON serializer options. /// The deserialized instance. - public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type type, JsonSerializerOptions options) + public override OpenIddictMessage Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (type == null) + if (typeToConvert == null) { - throw new ArgumentNullException(nameof(type)); + throw new ArgumentNullException(nameof(typeToConvert)); } using var document = JsonDocument.ParseValue(ref reader); - return type == typeof(OpenIddictMessage) ? new OpenIddictMessage(document.RootElement.Clone()) : - type == typeof(OpenIddictRequest) ? new OpenIddictRequest(document.RootElement.Clone()) : - type == typeof(OpenIddictResponse) ? (OpenIddictMessage) new OpenIddictResponse(document.RootElement.Clone()) : - throw new ArgumentException("The specified type is not supported.", nameof(type)); + return typeToConvert == typeof(OpenIddictMessage) ? new OpenIddictMessage(document.RootElement.Clone()) : + typeToConvert == typeof(OpenIddictRequest) ? new OpenIddictRequest(document.RootElement.Clone()) : + typeToConvert == typeof(OpenIddictResponse) ? (OpenIddictMessage) new OpenIddictResponse(document.RootElement.Clone()) : + throw new ArgumentException("The specified type is not supported.", nameof(typeToConvert)); } /// diff --git a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs index dcf49dd0..4f1071c3 100644 --- a/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs +++ b/src/OpenIddict.Abstractions/Primitives/OpenIddictParameter.cs @@ -88,11 +88,11 @@ namespace OpenIddict.Abstractions /// Determines whether the current /// instance is equal to the specified . /// - /// The other object to which to compare this instance. + /// The other object to which to compare this instance. /// true if the two instances are equal, false otherwise. - public bool Equals(OpenIddictParameter parameter) + public bool Equals(OpenIddictParameter other) { - return (left: Value, right: parameter.Value) switch + return (left: Value, right: other.Value) switch { // If the two parameters reference the same instance, return true. // Note: true will also be returned if the two parameters are null. @@ -200,10 +200,9 @@ namespace OpenIddict.Abstractions /// Determines whether the current /// instance is equal to the specified . /// - /// The other object to which to compare this instance. + /// The other object to which to compare this instance. /// true if the two instances are equal, false otherwise. - public override bool Equals(object value) - => value is OpenIddictParameter parameter && Equals(parameter); + public override bool Equals(object obj) => obj is OpenIddictParameter parameter && Equals(parameter); /// /// Returns the hash code of the current instance. diff --git a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs index d35a9a5a..e0bacd2f 100644 --- a/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs +++ b/src/OpenIddict.EntityFrameworkCore/OpenIddictEntityFrameworkCoreCustomizer.cs @@ -28,11 +28,11 @@ namespace OpenIddict.EntityFrameworkCore { } - public override void Customize([NotNull] ModelBuilder builder, [NotNull] DbContext context) + public override void Customize([NotNull] ModelBuilder modelBuilder, [NotNull] DbContext context) { - if (builder == null) + if (modelBuilder == null) { - throw new ArgumentNullException(nameof(builder)); + throw new ArgumentNullException(nameof(modelBuilder)); } if (context == null) @@ -41,9 +41,9 @@ namespace OpenIddict.EntityFrameworkCore } // Register the OpenIddict entity sets. - builder.UseOpenIddict(); + modelBuilder.UseOpenIddict(); - base.Customize(builder, context); + base.Customize(modelBuilder, context); } } } \ No newline at end of file diff --git a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs index ecee7a3d..e9c404d7 100644 --- a/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs +++ b/test/OpenIddict.Abstractions.Tests/Primitives/OpenIddictConverterTests.cs @@ -21,9 +21,9 @@ namespace OpenIddict.Abstractions.Tests.Primitives var converter = new OpenIddictConverter(); // Act and assert - var exception = Assert.Throws(() => converter.CanConvert(type: null)); + var exception = Assert.Throws(() => converter.CanConvert(typeToConvert: null)); - Assert.Equal("type", exception.ParamName); + Assert.Equal("typeToConvert", exception.ParamName); } [Theory] @@ -58,10 +58,10 @@ namespace OpenIddict.Abstractions.Tests.Primitives var exception = Assert.Throws(delegate { var reader = new Utf8JsonReader(); - return converter.Read(ref reader, type: null, options: null); + return converter.Read(ref reader, typeToConvert: null, options: null); }); - Assert.Equal("type", exception.ParamName); + Assert.Equal("typeToConvert", exception.ParamName); } [Theory] @@ -87,7 +87,7 @@ namespace OpenIddict.Abstractions.Tests.Primitives }); Assert.StartsWith("The specified type is not supported.", exception.Message); - Assert.Equal("type", exception.ParamName); + Assert.Equal("typeToConvert", exception.ParamName); } [Theory]