Skip to content

Commit

Permalink
Fix sonar warnings
Browse files Browse the repository at this point in the history
Signed-off-by: krivchenko_kv <kvkrivchenko@activebc.ru>
  • Loading branch information
krivchenko_kv committed Sep 17, 2024
1 parent 0ae0f32 commit 4ab2c39
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

private readonly ILogger<WeatherForecastController> _logger;

Expand Down
8 changes: 8 additions & 0 deletions src/Samples/Sample.Images.Worker/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
2 changes: 1 addition & 1 deletion src/Samples/Sample.Nats.WebApi/PingConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class PingConsumer(ILogger<PingConsumer> logger) : IConsumer<PingMessage>
{
private readonly ILogger _logger = logger;

public IConsumerContext Context { get; set; }
public IConsumerContext Context { get; set; } = default!;

public Task OnHandle(PingMessage message)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ namespace SlimMessageBus.Host.AzureEventHub;
/// </summary>
public class EhPartitionConsumerForResponses : EhPartitionConsumer
{
private readonly RequestResponseSettings _requestResponseSettings;

public EhPartitionConsumerForResponses(EventHubMessageBus messageBus, RequestResponseSettings requestResponseSettings, GroupPathPartitionId pathGroupPartition)
: base(messageBus, pathGroupPartition)
{
_requestResponseSettings = requestResponseSettings ?? throw new ArgumentNullException(nameof(requestResponseSettings));
if (requestResponseSettings == null) throw new ArgumentNullException(nameof(requestResponseSettings));

MessageProcessor = new ResponseMessageProcessor<EventData>(MessageBus.LoggerFactory, _requestResponseSettings, MessageBus, messagePayloadProvider: eventData => eventData.EventBody.ToArray());
CheckpointTrigger = new CheckpointTrigger(_requestResponseSettings, MessageBus.LoggerFactory);
MessageProcessor = new ResponseMessageProcessor<EventData>(MessageBus.LoggerFactory, requestResponseSettings, MessageBus, messagePayloadProvider: eventData => eventData.EventBody.ToArray());
CheckpointTrigger = new CheckpointTrigger(requestResponseSettings, MessageBus.LoggerFactory);
}
}
4 changes: 2 additions & 2 deletions src/SlimMessageBus.Host.Kafka/Consumer/KafkaGroupConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ protected virtual void OnOffsetsCommitted(CommittedOffsets e)
{
if (e.Error.IsError || e.Error.IsFatal)
{
Logger.LogWarning("Group [{Group}]: Failed to commit offsets: [{Offsets}], error: {error}", Group, string.Join(", ", e.Offsets), e.Error.Reason);
Logger.LogWarning("Group [{Group}]: Failed to commit offsets: [{Offsets}], error: {Error}", Group, string.Join(", ", e.Offsets), e.Error.Reason);
}
else
{
Expand All @@ -235,7 +235,7 @@ protected virtual void OnClose()

protected virtual void OnStatistics(string json)
{
Logger.LogTrace("Group [{Group}]: Statistics: {statistics}", Group, json);
Logger.LogTrace("Group [{Group}]: Statistics: {Statistics}", Group, json);
}

#region Implementation of IKafkaCoordinator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class OutboxForwardingPublishInterceptor<T>(
OutboxSettings outboxSettings)
: OutboxForwardingPublishInterceptor, IInterceptorWithOrder, IPublishInterceptor<T>, IDisposable where T : class
{
static readonly internal string SkipOutboxHeader = "__SkipOutbox";
internal const string SkipOutboxHeader = "__SkipOutbox";

private readonly ILogger _logger = logger;
private readonly IOutboxRepository _outboxRepository = outboxRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ async internal Task<int> SendMessages(IServiceProvider serviceProvider, IOutboxR
if (messageType == null)
{
abortedIds.Add(outboxMessage.Id);
_logger.LogError("Outbox message with Id {id} - the MessageType {messageType} is not recognized. The type might have been renamed or moved namespaces.", outboxMessage.Id, outboxMessage.MessageType);
_logger.LogError("Outbox message with Id {Id} - the MessageType {MessageType} is not recognized. The type might have been renamed or moved namespaces.", outboxMessage.Id, outboxMessage.MessageType);
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public abstract class CommonSqlMigrationService<TRepository, TSettings>
protected TRepository Repository { get; }
public ISqlTransactionService TransactionService { get; }

public CommonSqlMigrationService(ILogger logger, TRepository repository, ISqlTransactionService transactionService, TSettings settings)
protected CommonSqlMigrationService(ILogger logger, TRepository repository, ISqlTransactionService transactionService, TSettings settings)
{
Logger = logger;
Settings = settings;
Expand Down
2 changes: 1 addition & 1 deletion src/SlimMessageBus.Host/Consumer/AbstractConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class AbstractConsumer : IAsyncDisposable, IConsumerControl

protected CancellationToken CancellationToken => _cancellationTokenSource.Token;

public AbstractConsumer(ILogger logger)
protected AbstractConsumer(ILogger logger)
{
Logger = logger;
}
Expand Down
6 changes: 3 additions & 3 deletions src/SlimMessageBus.Host/MessageBusBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ protected virtual void BuildPendingRequestStore()
private Dictionary<Type, ProducerSettings> BuildProducerByBaseMessageType()
{
var producerByBaseMessageType = Settings.Producers.ToDictionary(producerSettings => producerSettings.MessageType);

foreach (var consumerSettings in Settings.Consumers.Where(x => x.ResponseType != null))
{
// A response type can be used across different requests hence TryAdd
Expand Down Expand Up @@ -314,7 +314,7 @@ public void Dispose()
GC.SuppressFinalize(this);
}

protected void Dispose(bool disposing)
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
Expand Down Expand Up @@ -717,7 +717,7 @@ public virtual Task<Exception> OnResponseArrived(byte[] responsePayload, string
public virtual bool IsMessageScopeEnabled(ConsumerSettings consumerSettings, IDictionary<string, object> consumerContextProperties)
=> consumerSettings.IsMessageScopeEnabled ?? Settings.IsMessageScopeEnabled ?? true;

public virtual IMessageScope CreateMessageScope(ConsumerSettings consumerSettings, object message, IDictionary<string, object> consumerContextProperties, IServiceProvider currentServiceProvider = null)
public virtual IMessageScope CreateMessageScope(ConsumerSettings consumerSettings, object message, IDictionary<string, object> consumerContextProperties, IServiceProvider currentServiceProvider)
{
var createMessageScope = IsMessageScopeEnabled(consumerSettings, consumerContextProperties);
return new MessageScopeWrapper(_logger, currentServiceProvider ?? Settings.ServiceProvider, createMessageScope, message);
Expand Down
4 changes: 2 additions & 2 deletions src/SlimMessageBus.Host/MessageWithHeadersSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private int WriteObject(byte[] payload, int index, object v)
payload[index] = TypeIdGuid;
return 1 + WriteGuid(payload, index + 1, g);
default:
throw new InvalidOperationException($"Not supported header value type {v?.GetType().FullName ?? "(null)"}");
throw new InvalidOperationException($"Not supported header value type {v.GetType().FullName ?? "(null)"}");
}
}

Expand All @@ -95,7 +95,7 @@ private int CalculateWriteObjectByteLength(object v)
int _ => sizeof(int),
long _ => sizeof(long),
Guid _ => 16,
_ => throw new InvalidOperationException($"Not supported header value type {v?.GetType().FullName ?? "(null)"}"),
_ => throw new InvalidOperationException($"Not supported header value type {v.GetType().FullName ?? "(null)"}"),
};
return 1 + byteLength;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

internal class PublishInterceptorPipeline : ProducerInterceptorPipeline<PublishContext>
{
private readonly IEnumerable<object> _publishInterceptors;
private readonly Func<object, object, Func<Task>, IProducerContext, Task> _publishInterceptorFunc;
private IEnumerator<object> _publishInterceptorsEnumerator;
private bool _publishInterceptorsVisited = false;

public PublishInterceptorPipeline(MessageBusBase bus, object message, ProducerSettings producerSettings, IMessageBusTarget targetBus, PublishContext context, IEnumerable<object> producerInterceptors, IEnumerable<object> publishInterceptors)
: base(bus, message, producerSettings, targetBus, context, producerInterceptors)
{
_publishInterceptors = publishInterceptors;
_publishInterceptorFunc = bus.RuntimeTypeCache.PublishInterceptorType[message.GetType()];
_publishInterceptorsVisited = publishInterceptors is null;
_publishInterceptorsEnumerator = _publishInterceptors?.GetEnumerator();
_publishInterceptorsEnumerator = publishInterceptors?.GetEnumerator();
}

public async Task<object> Next()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class ConcurrentMessageProcessorQueueTests
{
[Fact]
public async void When_Enqueue_Given_FourMessagesEnqueued_Then_ProcessMessageIsCalledOnFirstTwoThenTwoAfterThat()
public async Task When_Enqueue_Given_FourMessagesEnqueued_Then_ProcessMessageIsCalledOnFirstTwoThenTwoAfterThat()
{
// Arrange
var messageProcessor = new Mock<IMessageProcessor<object>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class MessageProcessorQueueTests
{
[Fact]
public async void When_Enqueue_Given_TwoMessagesEnqueued_Then_ProcessMessageIsCalledOn1stMessageAndOn2ndAfterThat()
public async Task When_Enqueue_Given_TwoMessagesEnqueued_Then_ProcessMessageIsCalledOn1stMessageAndOn2ndAfterThat()
{
// Arrange
var messageProcessor = new Mock<IMessageProcessor<object>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void When_GenerateGetterFunc_Given_TaskOfT_Then_ResultOfTaskIsObtained()
}

[Fact]
public async void When_GenerateMethodCallToFunc_Given_ConsumerWithOnHandlerAsyncMethodWithTwoArguments_Then_MethodIsProperlyInvoked()
public async Task When_GenerateMethodCallToFunc_Given_ConsumerWithOnHandlerAsyncMethodWithTwoArguments_Then_MethodIsProperlyInvoked()
{
// arrange
var message = new SomeMessage();
Expand Down Expand Up @@ -61,7 +61,7 @@ public void When_GenerateGenericMethodCallToFunc_Given_GenericMethid_Then_Method
}

[Fact]
public async void When_TaskOfObjectContinueWithTaskOfTypeFunc_Given_TaskOfObject_Then_TaskTypedIsObtained()
public async Task When_TaskOfObjectContinueWithTaskOfTypeFunc_Given_TaskOfObject_Then_TaskTypedIsObtained()
{
// arrange
var taskOfObject = Task.FromResult<object>(10);
Expand Down

0 comments on commit 4ab2c39

Please sign in to comment.