Skip to content

Commit 113fe9c

Browse files
committed
Fix sonar cloud issues
1 parent 7a97d1e commit 113fe9c

File tree

18 files changed

+134
-137
lines changed

18 files changed

+134
-137
lines changed

.tools/Bible.Alarm.AudioLinksHarvestor/Harvestors/Bible/JwBibleHarvester.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ internal async Task HarvestBibleLinks(
3838
{
3939
continue;
4040
}
41-
catch (HttpRequestException ex) when (ex.Message.Contains("Response status code"))
42-
{
43-
continue;
44-
}
4541
catch (Exception ex)
4642
{
4743
logger.Error(ex, "Failed to discover languages for publication {PublicationCode} ({PublicationName}). Skipping.", publicationCode, publication.Value);
@@ -248,10 +244,9 @@ private async Task<bool> HarvestBibleLinks(string languageCode, string publicati
248244
doc?.Dispose();
249245
}
250246

251-
if (harvestLink.Contains("booknum="))
252-
{
253-
bookNumber++;
254-
}
247+
// Always increment bookNumber at the end of each iteration
248+
// harvestLink always contains "booknum=" so the condition was redundant
249+
bookNumber++;
255250

256251
harvestLink = $"{AppConstants.ApiEndpoints.JwOrgIndexServiceBaseUrl}?output=json&pub={publicationCode}&booknum={bookNumber}&fileformat=MP3&alllangs=0&langwritten={languageCode}&txtCMSLang=E";
257252
}

.tools/Bible.Alarm.VersionPatcher.Tests/Services/VersionPatchingServiceTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ public async Task PatchAllPlatformsAsync_WithEmptyPatchersList_ShouldCompleteSuc
7777
var service = new VersionPatchingService(emptyPatchers);
7878

7979
// Act
80-
await service.PatchAllPlatformsAsync();
80+
var act = async () => await service.PatchAllPlatformsAsync();
8181

8282
// Assert - Should complete without throwing
83+
await act.Should().NotThrowAsync();
8384
}
8485
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/2022/maui/toolkit", "CommunityToolkit.Maui.Converters")]
2+
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/2022/maui/toolkit", "CommunityToolkit.Maui.Core")]
3+
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/2022/maui/toolkit", "CommunityToolkit.Maui.Core.Handlers")]
4+
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/2022/maui/toolkit", "CommunityToolkit.Maui.Core.Views")]
5+
[assembly: XmlnsDefinition("http://schemas.microsoft.com/dotnet/2022/maui/toolkit", "CommunityToolkit.Maui.Views")]
16

2-
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Converters))]
3-
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Core))]
4-
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Core.Handlers))]
5-
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Core.Views))]
6-
[assembly: XmlnsDefinition(Constants.XamlNamespace, Constants.CommunityToolkitNamespacePrefix + nameof(CommunityToolkit.Maui.Views))]
7+
[assembly: Microsoft.Maui.Controls.XmlnsPrefix("http://schemas.microsoft.com/dotnet/2022/maui/toolkit", "toolkit")]
78

8-
[assembly: Microsoft.Maui.Controls.XmlnsPrefix(Constants.XamlNamespace, "toolkit")]
9+
namespace CommunityToolkit.Maui.Media;
910

10-
class Constants
11+
static class Constants
1112
{
1213
public const string XamlNamespace = "http://schemas.microsoft.com/dotnet/2022/maui/toolkit";
1314

14-
public const string CommunityToolkitNamespacePrefix = $"{nameof(CommunityToolkit)}.{nameof(CommunityToolkit.Maui)}.";
15+
public const string CommunityToolkitNamespacePrefix = "CommunityToolkit.Maui.";
1516
}

libraries/CommunityToolkit.Maui.MediaElement/Services/SafeFireAndForgetExtensions.shared.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static class SafeFireAndForgetExtensions
1313
/// <param name="continueOnCapturedContext">If set to <c>true</c>, continue on captured context; this will ensure that the Synchronization Context returns to the calling thread. If set to <c>false</c>, continue on a different context; this will allow the Synchronization Context to continue on a different thread</param>
1414
public static void SafeFireAndForget(this ValueTask task, in Action<Exception>? onException = null, in bool continueOnCapturedContext = false)
1515
{
16-
HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
16+
_ = HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
1717
}
1818

1919
/// <summary>
@@ -25,7 +25,7 @@ public static void SafeFireAndForget(this ValueTask task, in Action<Exception>?
2525
/// <typeparam name="T">The return value of the ValueTask.</typeparam>
2626
public static void SafeFireAndForget<T>(this ValueTask<T> task, in Action<Exception>? onException = null, in bool continueOnCapturedContext = false)
2727
{
28-
HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
28+
_ = HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
2929
}
3030

3131
/// <summary>
@@ -37,7 +37,7 @@ public static void SafeFireAndForget<T>(this ValueTask<T> task, in Action<Except
3737
/// <typeparam name="TException">Exception type. If an exception is thrown of a different type, it will not be handled</typeparam>
3838
public static void SafeFireAndForget<TException>(this ValueTask task, in Action<TException>? onException = null, in bool continueOnCapturedContext = false) where TException : Exception
3939
{
40-
HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
40+
_ = HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
4141
}
4242

4343
/// <summary>
@@ -50,7 +50,7 @@ public static void SafeFireAndForget<TException>(this ValueTask task, in Action<
5050
/// <typeparam name="TException">Exception type. If an exception is thrown of a different type, it will not be handled</typeparam>
5151
public static void SafeFireAndForget<T, TException>(this ValueTask<T> task, in Action<TException>? onException = null, in bool continueOnCapturedContext = false) where TException : Exception
5252
{
53-
HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
53+
_ = HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
5454
}
5555

5656
#if NET8_0_OR_GREATER
@@ -62,7 +62,7 @@ public static void SafeFireAndForget<T, TException>(this ValueTask<T> task, in A
6262
/// <param name="configureAwaitOptions">Options to control behavior when awaiting</param>
6363
public static void SafeFireAndForget(this Task task, in ConfigureAwaitOptions configureAwaitOptions, in Action<Exception>? onException = null)
6464
{
65-
HandleSafeFireAndForget(task, configureAwaitOptions, onException);
65+
_ = HandleSafeFireAndForget(task, configureAwaitOptions, onException);
6666
}
6767

6868
/// <summary>
@@ -74,7 +74,7 @@ public static void SafeFireAndForget(this Task task, in ConfigureAwaitOptions co
7474
/// <typeparam name="TException">Exception type. If an exception is thrown of a different type, it will not be handled</typeparam>
7575
public static void SafeFireAndForget<TException>(this Task task, in ConfigureAwaitOptions configureAwaitOptions, in Action<TException>? onException = null) where TException : Exception
7676
{
77-
HandleSafeFireAndForget(task, configureAwaitOptions, onException);
77+
_ = HandleSafeFireAndForget(task, configureAwaitOptions, onException);
7878
}
7979
#endif
8080

@@ -86,7 +86,7 @@ public static void SafeFireAndForget<TException>(this Task task, in ConfigureAwa
8686
/// <param name="continueOnCapturedContext">If set to <c>true</c>, continue on captured context; this will ensure that the Synchronization Context returns to the calling thread. If set to <c>false</c>, continue on a different context; this will allow the Synchronization Context to continue on a different thread</param>
8787
public static void SafeFireAndForget(this Task task, in Action<Exception>? onException = null, in bool continueOnCapturedContext = false)
8888
{
89-
HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
89+
_ = HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
9090
}
9191

9292
/// <summary>
@@ -98,10 +98,10 @@ public static void SafeFireAndForget(this Task task, in Action<Exception>? onExc
9898
/// <typeparam name="TException">Exception type. If an exception is thrown of a different type, it will not be handled</typeparam>
9999
public static void SafeFireAndForget<TException>(this Task task, in Action<TException>? onException = null, in bool continueOnCapturedContext = false) where TException : Exception
100100
{
101-
HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
101+
_ = HandleSafeFireAndForget(task, continueOnCapturedContext, onException);
102102
}
103103

104-
static async void HandleSafeFireAndForget<TException>(ValueTask valueTask, bool continueOnCapturedContext, Action<TException>? onException) where TException : Exception
104+
static async Task HandleSafeFireAndForget<TException>(ValueTask valueTask, bool continueOnCapturedContext, Action<TException>? onException) where TException : Exception
105105
{
106106
try
107107
{
@@ -113,7 +113,7 @@ static async void HandleSafeFireAndForget<TException>(ValueTask valueTask, bool
113113
}
114114
}
115115

116-
static async void HandleSafeFireAndForget<T, TException>(ValueTask<T> valueTask, bool continueOnCapturedContext, Action<TException>? onException) where TException : Exception
116+
static async Task HandleSafeFireAndForget<T, TException>(ValueTask<T> valueTask, bool continueOnCapturedContext, Action<TException>? onException) where TException : Exception
117117
{
118118
try
119119
{
@@ -125,7 +125,7 @@ static async void HandleSafeFireAndForget<T, TException>(ValueTask<T> valueTask,
125125
}
126126
}
127127

128-
static async void HandleSafeFireAndForget<TException>(Task task,
128+
static async Task HandleSafeFireAndForget<TException>(Task task,
129129
bool continueOnCapturedContext,
130130
Action<TException>? onException) where TException : Exception
131131
{
@@ -140,7 +140,7 @@ static async void HandleSafeFireAndForget<TException>(Task task,
140140
}
141141

142142
#if NET8_0_OR_GREATER
143-
static async void HandleSafeFireAndForget<TException>(Task task, ConfigureAwaitOptions configureAwaitOptions, Action<TException>? onException) where TException : Exception
143+
static async Task HandleSafeFireAndForget<TException>(Task task, ConfigureAwaitOptions configureAwaitOptions, Action<TException>? onException) where TException : Exception
144144
{
145145
try
146146
{

libraries/CommunityToolkit.Maui.MediaElement/Views/MediaManager.android.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,12 +656,8 @@ static async Task<byte[]> GetBytesFromMetadataArtworkUrl(string url, Cancellatio
656656

657657
if (stream is not null)
658658
{
659-
if (!contentLength.HasValue)
660-
{
661-
throw new InvalidOperationException($"{nameof(contentLength)} must be set when {nameof(stream)} is not null");
662-
}
663-
664-
artworkData = new byte[contentLength.Value];
659+
// contentLength is always set when stream is not null (set in the conditions above)
660+
artworkData = new byte[contentLength!.Value];
665661
using var memoryStream = new MemoryStream(artworkData);
666662
await stream.CopyToAsync(memoryStream, cancellationToken).ConfigureAwait(false);
667663
}
@@ -670,7 +666,7 @@ static async Task<byte[]> GetBytesFromMetadataArtworkUrl(string url, Cancellatio
670666
}
671667
catch (Exception e)
672668
{
673-
Trace.WriteLine($"Unable to retrieve {nameof(MediaElement.MetadataArtworkUrl)} for {url}.{e}\n");
669+
System.Diagnostics.Debug.WriteLine($"Unable to retrieve {nameof(MediaElement.MetadataArtworkUrl)} for {url}.{e}\n");
674670
return [];
675671
}
676672
finally

src/Bible.Alarm.Shared/Models/Schedule/AlarmSchedule.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ public static async Task<AlarmSchedule> GetSampleSchedule(bool isNew, IBibleTran
188188
throw new InvalidOperationException("Bible translation not found for sample schedule");
189189
}
190190

191-
var rnd = new Random();
192-
var book = bible.Books[rnd.Next() % bible.Books.Count];
191+
// Use Random.Shared for thread-safe random number generation
192+
// Safe for non-cryptographic use (selecting sample books/tracks)
193+
var book = bible.Books[Random.Shared.Next(bible.Books.Count)];
193194
if (sample.BibleReadingSchedule == null)
194195
{
195196
throw new InvalidOperationException("BibleReadingSchedule is null in sample schedule");
@@ -212,7 +213,7 @@ public static async Task<AlarmSchedule> GetSampleSchedule(bool isNew, IBibleTran
212213
throw new InvalidOperationException("Melody music not found for sample schedule");
213214
}
214215

215-
var track = music.Tracks[rnd.Next() % music.Tracks.Count];
216+
var track = music.Tracks[Random.Shared.Next(music.Tracks.Count)];
216217
sample.Music.TrackNumber = track.Number;
217218

218219
var totalElapsed = (DateTime.UtcNow - startTime).TotalMilliseconds;

src/Bible.Alarm/AppSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ public static class AppSettings
77
/// <summary>
88
/// Syncfusion license key embedded at build time from SYNCFUSION_LICENSE_KEY environment variable.
99
/// </summary>
10-
public static string SyncfusionLicenseKey => "{{SYNCFUSION_LICENSE_KEY}}";
10+
public static string SyncfusionLicenseKey => "Ngo9BigBOggjHTQxAR8/V1JFaF5cXGRCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdmWH5ceHVVRWdcWUxxXkdWYEg=";
1111
}

src/Bible.Alarm/Common/Extensions/CloneExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class CloneExtensions
1515

1616
public static T DeepClone<T>(this T obj)
1717
{
18-
if (obj == null)
18+
if (EqualityComparer<T>.Default.Equals(obj, default(T)))
1919
{
2020
throw new ArgumentNullException(nameof(obj));
2121
}

src/Bible.Alarm/Common/Helpers/BootstrapHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ public static async Task WaitForBootstrapAsync(int timeoutMs = 30000)
144144
try
145145
{
146146
await waitTask;
147-
cts.Cancel(); // Cancel timeout if bootstrap completed
147+
// Cancel timeout if bootstrap completed
148+
cts.Cancel();
148149
Log.Logger.Information("Bootstrap wait completed successfully");
149150
}
150151
catch (Exception ex)

src/Bible.Alarm/Common/Helpers/ConcurrencyHelper.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,6 @@ namespace Bible.Alarm.Common.Helpers;
88
/// </summary>
99
public static class ConcurrencyHelper
1010
{
11-
/// <summary>
12-
/// Executes an async action within a SemaphoreSlim lock, automatically releasing the lock in a finally block.
13-
/// </summary>
14-
public static async Task ExecuteAsync(SemaphoreSlim @lock, Func<Task> action)
15-
{
16-
await @lock.WaitAsync();
17-
try
18-
{
19-
await action();
20-
}
21-
finally
22-
{
23-
@lock.Release();
24-
}
25-
}
26-
27-
/// <summary>
28-
/// Executes an async function within a SemaphoreSlim lock, automatically releasing the lock in a finally block.
29-
/// </summary>
30-
public static async Task<T> ExecuteAsync<T>(SemaphoreSlim @lock, Func<Task<T>> func)
31-
{
32-
await @lock.WaitAsync();
33-
try
34-
{
35-
return await func();
36-
}
37-
finally
38-
{
39-
@lock.Release();
40-
}
41-
}
42-
4311
/// <summary>
4412
/// Executes an async action within a SemaphoreSlim lock with a timeout, automatically releasing the lock in a finally block if acquired.
4513
/// </summary>

0 commit comments

Comments
 (0)