Skip to content

Commit 634023e

Browse files
chore: Fixing some low priority sonarqube issues (#1668)
* chore: some fixes * chore: More sonarqube fixes * chore: remove whitespace * chore: Address comments * chore: Add import * fix: Revert add --------- Co-authored-by: Michael Clayson <michael.clayson1@nhs.net>
1 parent 1980619 commit 634023e

24 files changed

Lines changed: 71 additions & 72 deletions

File tree

application/CohortManager/src/Functions/CaasIntegration/RetrieveMeshFile/RetrieveMeshFile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public RetrieveMeshFile(ILogger<RetrieveMeshFile> logger, IMeshToBlobTransferHan
4242
[Function("RetrieveMeshFile")]
4343
public async Task RunAsync([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer)
4444
{
45-
_logger.LogInformation("C# Timer trigger function executed at: ,{datetime}", DateTime.UtcNow);
45+
_logger.LogInformation("C# Timer trigger function executed at: ,{DateTime}", DateTime.UtcNow);
4646

4747
static bool messageFilter(MessageMetaData i) => true; // No current filter defined there might be business rules here
4848

@@ -65,7 +65,7 @@ public async Task RunAsync([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer)
6565

6666
if (myTimer.ScheduleStatus is not null)
6767
{
68-
_logger.LogInformation("Next timer schedule at: {scheduleStatus}", myTimer.ScheduleStatus.Next);
68+
_logger.LogInformation("Next timer schedule at: {ScheduleStatus}", myTimer.ScheduleStatus.Next);
6969
}
7070
}
7171

@@ -127,7 +127,7 @@ private async Task<bool> ShouldExecuteHandShake()
127127
return true;
128128

129129
}
130-
_logger.LogInformation("Next handshake scheduled for {nextHandShakeDateTime}", nextHandShakeDateTime);
130+
_logger.LogInformation("Next handshake scheduled for {NextHandShakeDateTime}", nextHandShakeDateTime);
131131
return false;
132132
}
133133

application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/ProcessFileClasses/CallDurableDemographicFunc.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace NHS.Screening.ReceiveCaasFile;
22

33

4-
using System.Net.Http.Headers;
54
using System.Text.Json;
65
using Common;
7-
using Microsoft.Azure.Functions.Worker.Extensions.Abstractions;
86
using Microsoft.Extensions.Logging;
97
using Microsoft.Extensions.Options;
108
using Model;
@@ -83,7 +81,7 @@ public async Task<bool> PostDemographicDataAsync(List<ParticipantDemographic> pa
8381

8482
if (finalStatus == WorkFlowStatus.Completed)
8583
{
86-
_logger.LogWarning("Durable function completed {finalStatus}", finalStatus);
84+
_logger.LogWarning("Durable function completed {FinalStatus}", finalStatus);
8785
return true;
8886
}
8987
else

application/CohortManager/src/Functions/CaasIntegration/receiveCaasFile/receiveCaasFile.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace NHS.Screening.ReceiveCaasFile;
1010
using Common;
1111
using DataServices.Client;
1212
using Microsoft.Extensions.Options;
13-
using Azure.Messaging.ServiceBus;
1413

1514
public class ReceiveCaasFile
1615
{
@@ -119,7 +118,7 @@ public async Task Run([BlobTrigger("inbound/{name}", Connection = "caasfolder_ST
119118
public async Task<ScreeningLkp> GetScreeningService(FileNameParser fileNameParser)
120119
{
121120
var screeningWorkflowId = fileNameParser.GetScreeningService();
122-
_logger.LogInformation("Screening Acronym {screeningWorkflowId}", screeningWorkflowId);
121+
_logger.LogInformation("Screening Acronym {ScreeningWorkflowId}", screeningWorkflowId);
123122

124123
ScreeningLkp screeningService = await _screeningLkpClient.GetSingleByFilter(x => x.ScreeningWorkflowId == screeningWorkflowId)
125124
?? throw new ArgumentException("Could not get screening service data for screening id: " + screeningWorkflowId);

application/CohortManager/src/Functions/DemographicServices/ManageCaasSubscription/ManageCaasSubscription.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@ namespace NHS.CohortManager.DemographicServices;
77
using Microsoft.Extensions.Logging;
88
using Microsoft.Extensions.Options;
99
using Common;
10-
using System.Collections.Specialized;
1110
using System.Text;
1211
using DataServices.Core;
1312
using Model;
14-
using NHS.CohortManager.DemographicServices;
15-
using Common.Interfaces;
1613
using System.Text.Json;
1714
using System.Linq;
18-
using System.Security.Cryptography.X509Certificates;
1915

2016
/// <summary>
2117
/// Azure Functions endpoints for managing CaaS subscriptions via MESH and data services.
@@ -30,6 +26,7 @@ public class ManageCaasSubscription
3026
private readonly IDataServiceAccessor<NemsSubscription> _nemsSubscriptionAccessor;
3127
private readonly IMeshPoller _meshPoller;
3228
private readonly IExceptionHandler _exceptionHandler;
29+
private const string? nhsNum = "nhsNumber";
3330

3431
public ManageCaasSubscription(
3532
ILogger<ManageCaasSubscription> logger,
@@ -60,9 +57,9 @@ public ManageCaasSubscription(
6057
[Function("Subscribe")]
6158
public async Task<HttpResponseData> Subscribe([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req)
6259
{
60+
string? nhsNumber = req.Query[nhsNum];
6361
try
6462
{
65-
var nhsNumber = req.Query["nhsNumber"];
6663
if (!ValidationHelper.ValidateNHSNumber(nhsNumber!))
6764
{
6865
return await _createResponse.CreateHttpResponseWithBodyAsync(HttpStatusCode.BadRequest, req, "NHS number is required and must be valid format.");
@@ -117,7 +114,7 @@ public async Task<HttpResponseData> Subscribe([HttpTrigger(AuthorizationLevel.An
117114
_logger.LogError(ex, "Error sending CAAS subscribe request");
118115
try
119116
{
120-
string? rawNhs = req.Query["nhsNumber"];
117+
string? rawNhs = req.Query[nhsNum];
121118
var nhsForLog = ValidationHelper.ValidateNHSNumber(rawNhs!) ? rawNhs! : string.Empty;
122119
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, nhsForLog, nameof(ManageCaasSubscription), "", string.Empty);
123120
}
@@ -242,7 +239,7 @@ public async Task<HttpResponseData> SubscribeMany([HttpTrigger(AuthorizationLeve
242239
[Function("Unsubscribe")]
243240
public async Task<HttpResponseData> Unsubscribe([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req)
244241
{
245-
var nhsNumber = req.Query["nhsNumber"];
242+
var nhsNumber = req.Query[nhsNum];
246243
if (!ValidationHelper.ValidateNHSNumber(nhsNumber!))
247244
{
248245
return await _createResponse.CreateHttpResponseWithBodyAsync(HttpStatusCode.BadRequest, req, "NHS number is required and must be valid format.");
@@ -264,7 +261,7 @@ public async Task<HttpResponseData> CheckSubscriptionStatus([HttpTrigger(Authori
264261
{
265262
_logger.LogInformation("Received check subscription request");
266263

267-
string? nhsNumber = req.Query["nhsNumber"];
264+
string? nhsNumber = req.Query[nhsNum];
268265

269266
if (!ValidationHelper.ValidateNHSNumber(nhsNumber!))
270267
{
@@ -287,7 +284,7 @@ public async Task<HttpResponseData> CheckSubscriptionStatus([HttpTrigger(Authori
287284
_logger.LogError(ex, "Error checking subscription status");
288285
try
289286
{
290-
string? rawNhs = req.Query["nhsNumber"];
287+
string? rawNhs = req.Query[nhsNum];
291288
var nhsForLog = ValidationHelper.ValidateNHSNumber(rawNhs!) ? rawNhs! : string.Empty;
292289
await _exceptionHandler.CreateSystemExceptionLogFromNhsNumber(ex, nhsForLog, nameof(ManageCaasSubscription), "", string.Empty);
293290
}

application/CohortManager/src/Functions/NemsSubscriptionService/NemsMeshRetrieval/NemsMeshRetrieval.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
namespace NHS.Screening.NemsMeshRetrieval;
22

33
using System;
4-
using System.Diagnostics.CodeAnalysis;
54
using System.Globalization;
6-
using System.Text;
75
using System.Text.Json;
86
using System.Threading.Tasks;
97
using Common;
@@ -42,7 +40,7 @@ public NemsMeshRetrieval(ILogger<NemsMeshRetrieval> logger, IMeshToBlobTransferH
4240
[Function("RetrieveNemsMeshFile")]
4341
public async Task RunAsync([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer)
4442
{
45-
_logger.LogInformation("C# Timer trigger function executed at: ,{datetime}", DateTime.UtcNow);
43+
_logger.LogInformation("C# Timer trigger function executed at: ,{Datetime}", DateTime.UtcNow);
4644

4745
static bool messageFilter(MessageMetaData i) => true; // No current filter defined there might be business rules here
4846

@@ -65,7 +63,7 @@ public async Task RunAsync([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer)
6563

6664
if (myTimer.ScheduleStatus is not null)
6765
{
68-
_logger.LogInformation("Next timer schedule at: {scheduleStatus}", myTimer.ScheduleStatus.Next);
66+
_logger.LogInformation("Next timer schedule at: {ScheduleStatus}", myTimer.ScheduleStatus.Next);
6967
}
7068
}
7169

@@ -127,7 +125,7 @@ private async Task<bool> ShouldExecuteHandShake()
127125
return true;
128126

129127
}
130-
_logger.LogInformation("Next handshake scheduled for {nextHandShakeDateTime}", nextHandShakeDateTime);
128+
_logger.LogInformation("Next handshake scheduled for {NextHandShakeDateTime}", nextHandShakeDateTime);
131129
return false;
132130
}
133131

application/CohortManager/src/Functions/ParticipantManagementServices/UpdateBlockedFlag/BlockParticipantHandler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class BlockParticipantHandler : IBlockParticipantHandler
1616
private readonly IDataServiceClient<ParticipantDemographic> _participantDemographicDataService;
1717
private readonly IHttpClientFunction _httpClient;
1818
private readonly UpdateBlockedFlagConfig _config;
19+
private static readonly string CultureInfo = "en-GB";
1920
public BlockParticipantHandler(ILogger<BlockParticipantHandler> logger,
2021
IDataServiceClient<ParticipantManagement> participantManagementDataService,
2122
IDataServiceClient<ParticipantDemographic> participantDemographicDataService,
@@ -253,12 +254,12 @@ private async Task<PdsDemographic> GetPDSParticipant(long nhsNumber)
253254
private static bool ValidateRecordsMatch(ParticipantDemographic participant, BlockParticipantDto dto)
254255
{
255256

256-
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd", new CultureInfo("en-GB"), DateTimeStyles.None, out var dtoDateOfBirth))
257+
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd", new CultureInfo(CultureInfo), DateTimeStyles.None, out var dtoDateOfBirth))
257258
{
258259
throw new FormatException("Date of Birth not in the correct format");
259260
}
260261

261-
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyyMMdd", new CultureInfo("en-GB"), DateTimeStyles.None, out var parsedDob))
262+
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyyMMdd", new CultureInfo(CultureInfo), DateTimeStyles.None, out var parsedDob))
262263
{
263264
return false;
264265
}
@@ -271,12 +272,12 @@ private static bool ValidateRecordsMatch(ParticipantDemographic participant, Blo
271272
private static bool ValidateRecordsMatch(PdsDemographic participant, BlockParticipantDto dto)
272273
{
273274

274-
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd", new CultureInfo("en-GB"), DateTimeStyles.None, out var dtoDateOfBirth))
275+
if (!DateOnly.TryParseExact(dto.DateOfBirth, "yyyy-MM-dd", new CultureInfo(CultureInfo), DateTimeStyles.None, out var dtoDateOfBirth))
275276
{
276277
throw new FormatException("Date of Birth not in the correct format");
277278
}
278279

279-
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyy-MM-dd", new CultureInfo("en-GB"), DateTimeStyles.None, out var parsedDob))
280+
if (!DateOnly.TryParseExact(participant.DateOfBirth, "yyyy-MM-dd", new CultureInfo(CultureInfo), DateTimeStyles.None, out var parsedDob))
280281
{
281282
return false;
282283
}

application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowMessageHandler/ReceiveServiceNowMessageFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymou
125125
}
126126
catch (JsonException ex)
127127
{
128-
_logger.LogError(ex, "Failed to deserialize json request body to type {type}", nameof(ReceiveServiceNowMessageRequestBody));
128+
_logger.LogError(ex, "Failed to deserialize json request body to type {Type}", nameof(ReceiveServiceNowMessageRequestBody));
129129
return _createResponse.CreateHttpResponse(HttpStatusCode.BadRequest, req);
130130
}
131131
catch (Exception ex)

application/CohortManager/src/Functions/ServiceNowIntegration/ServiceNowMessageHandler/ServiceNowClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private static HttpRequestMessage CreateRequest(string url, string json, string
156156

157157
if (!response.IsSuccessStatusCode)
158158
{
159-
_logger.LogError("Failed to refresh ServiceNow access token. StatusCode: {statusCode}", response.StatusCode);
159+
_logger.LogError("Failed to refresh ServiceNow access token. StatusCode: {StatusCode}", response.StatusCode);
160160
return null;
161161
}
162162

application/CohortManager/src/Functions/Shared/Common/AuthorizationClientCredentials.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public AuthorizationClientCredentials(IJwtTokenService jwtTokenService, HttpClie
4040

4141
if (response.StatusCode != HttpStatusCode.OK)
4242
{
43-
_logger.LogError("there was an error getting the bearer token from the NHS token service. Response: {resBody}", resBody);
43+
_logger.LogError("there was an error getting the bearer token from the NHS token service. Response: {ResBody}", resBody);
4444
return null;
4545
}
4646

application/CohortManager/src/Functions/Shared/Common/AzureQueueStorageHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public async Task<bool> AddAsync<T>(T message, string queueName)
3131
}
3232
catch (Exception ex)
3333
{
34-
_logger.LogError(ex, "There was an error while putting item on queue for queue: {queueName}", queueName);
34+
_logger.LogError(ex, "There was an error while putting item on queue for queue: {QueueName}", queueName);
3535
return false;
3636
}
3737
}

0 commit comments

Comments
 (0)