Skip to content

Commit

Permalink
Fix SonarCloud code smells (#328)
Browse files Browse the repository at this point in the history
  • Loading branch information
guibranco committed Feb 7, 2024
1 parent 6054e7c commit 5c38c07
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
<ProjectReference Include="..\CrispyWaffle\CrispyWaffle.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.19.0.84025" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
<PackageReference Include="NEST" Version="7.17.5" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.19.0.84025" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions Src/CrispyWaffle.Elmah/CrispyWaffle.Elmah.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<PackageReference Include="ElmahCore" Version="2.1.2" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.19.0.84025" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions Src/CrispyWaffle.Log4Net/CrispyWaffle.Log4Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<ProjectReference Include="..\CrispyWaffle\CrispyWaffle.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.19.0.84025" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions Src/CrispyWaffle.RabbitMQ/CrispyWaffle.RabbitMQ.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<ProjectReference Include="..\CrispyWaffle\CrispyWaffle.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.19.0.84025" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void SendToQueue<T>(T item, bool queueDeclare = true)
var properties = channel.CreateBasicProperties();
properties.Persistent = true;

channel.BasicPublish("", queueName, false, properties, body);
channel.BasicPublish(string.Empty, queueName, false, properties, body);

LogConsumer.Trace("Sent to queue {0} the item: {1}", queueName, json);
}
Expand Down
4 changes: 4 additions & 0 deletions Src/CrispyWaffle.Redis/CrispyWaffle.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.19.0.84025" />
</ItemGroup>

</Project>
4 changes: 4 additions & 0 deletions Src/CrispyWaffle.Utils/CrispyWaffle.Utils.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
<ProjectReference Include="..\CrispyWaffle\CrispyWaffle.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.19.0.84025" />
</ItemGroup>

</Project>
46 changes: 23 additions & 23 deletions Src/CrispyWaffle/Cache/MemoryCacheRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
namespace CrispyWaffle.Cache
{
/// <summary>
/// The memory cache helper class
/// The memory cache helper class.
/// </summary>
public class MemoryCacheRepository : ICacheRepository
{
/// <summary>
/// The data
/// The data.
/// </summary>
private static readonly ConcurrentDictionary<string, object> _data =
new ConcurrentDictionary<string, object>();

/// <summary>
/// The hash
/// The hash.
/// </summary>
private static readonly ConcurrentDictionary<string, object> _hash =
new ConcurrentDictionary<string, object>();
Expand All @@ -31,11 +31,11 @@ public class MemoryCacheRepository : ICacheRepository
/// <summary>
/// Stores the specified key.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type parameter.</typeparam>
/// <param name="value">The value.</param>
/// <param name="key">The key.</param>
/// <param name="ttl">This would be the TTL parameter, but it's not implemented in this type of cache (memory). Maybe in further version...</param>
/// <exception cref="OverflowException">The dictionary already contains the maximum number of elements (<see cref="System.Int32.MaxValue" />).</exception>
/// <exception cref="OverflowException">The dictionary already contains the maximum number of elements.</exception>
public void Set<T>(T value, string key, TimeSpan? ttl = null)
{
_data.AddOrUpdate(key, value, (_, _) => value);
Expand All @@ -44,24 +44,24 @@ public void Set<T>(T value, string key, TimeSpan? ttl = null)
/// <summary>
/// Sets the specified value.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type parameter.</typeparam>
/// <param name="value">The value.</param>
/// <param name="key">The key.</param>
/// <param name="subKey">The sub key.</param>
/// <exception cref="OverflowException">The dictionary already contains the maximum number of elements (<see cref="System.Int32.MaxValue" />).</exception>
/// <exception cref="OverflowException">The dictionary already contains the maximum number of elements.</exception>
public void Set<T>(T value, string key, string subKey)
{
var finalKey = $@"{key}-{subKey}";
var finalKey = $"{key}-{subKey}";
_hash.AddOrUpdate(finalKey, value, (_, _) => value);
}

/// <summary>
/// Gets the object with the specified key.
/// </summary>
/// <typeparam name="T">The type of object (the object will be cast to this type)</typeparam>
/// <typeparam name="T">The type of object (the object will be cast to this type).</typeparam>
/// <param name="key">The key.</param>
/// <returns>The object as <typeparamref name="T"/></returns>
/// <exception cref="InvalidOperationException">Throws when the object with the specified key doesn't exists</exception>
/// <returns>The object as <typeparamref name="T"/>The type parameter.</returns>
/// <exception cref="InvalidOperationException">Throws when the object with the specified key doesn't exist.</exception>
public T Get<T>(string key)
{
if (!_data.TryGetValue(key, out var value))
Expand All @@ -75,14 +75,14 @@ public T Get<T>(string key)
/// <summary>
/// Gets the specified key.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type parameter.</typeparam>
/// <param name="key">The key.</param>
/// <param name="subKey">The sub key.</param>
/// <returns></returns>
/// <exception cref="InvalidOperationException"></exception>
/// <returns>T.</returns>
/// <exception cref="InvalidOperationException">Unable to get the item with key {key} and sub key {subKey}.</exception>
public T Get<T>(string key, string subKey)
{
var finalKey = $@"{key}-{subKey}";
var finalKey = $"{key}-{subKey}";
if (!_hash.TryGetValue(finalKey, out var value))
{
throw new InvalidOperationException(
Expand All @@ -97,10 +97,10 @@ public T Get<T>(string key, string subKey)
/// Tries to get a value based on its key, if exists return true, else false.
/// The out parameter value is the object requested.
/// </summary>
/// <typeparam name="T">The type of object (the object will be cast to this type)</typeparam>
/// <typeparam name="T">The type of object (the object will be cast to this type).</typeparam>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
/// <returns>Returns <b>True</b> if the object with the key exists, false otherwise</returns>
/// <returns>Returns <b>True</b> if the object with the key exists, false otherwise.</returns>
public bool TryGet<T>(string key, out T value)
{
value = default;
Expand All @@ -116,15 +116,15 @@ public bool TryGet<T>(string key, out T value)
/// <summary>
/// Tries the get.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type parameter.</typeparam>
/// <param name="key">The key.</param>
/// <param name="subKey">The sub key.</param>
/// <param name="value">The value.</param>
/// <returns></returns>
/// <returns><c>true</c> if able to get the key and sub key, <c>false</c> otherwise.</returns>
public bool TryGet<T>(string key, string subKey, out T value)
{
value = default;
var finalKey = $@"{key}-{subKey}";
var finalKey = $"{key}-{subKey}";
if (!_hash.TryGetValue(finalKey, out var temp))
{
return false;
Expand Down Expand Up @@ -153,7 +153,7 @@ public void Remove(string key)
/// <param name="subKey">The sub key.</param>
public void Remove(string key, string subKey)
{
var finalKey = $@"{key}-{subKey}";
var finalKey = $"{key}-{subKey}";
if (_data.ContainsKey(finalKey))
{
_hash.TryRemove(finalKey, out _);
Expand All @@ -165,8 +165,8 @@ public void Remove(string key, string subKey)
/// </summary>
/// <param name="key">The key.</param>
/// <returns>
/// The timespan until this key is expired from the cache or 0 if it's already expired or doesn't exists.
/// As Memory Cache does not implements TTL or expire mechanism, this will always return 0, even if the key exists.
/// The timespan until this key is expired from the cache or 0 if it's already expired or doesn't exist.
/// As Memory Cache does not implement TTL or expire mechanism, this will always return 0, even if the key exists.
/// </returns>
public TimeSpan TTL(string key)
{
Expand Down
4 changes: 4 additions & 0 deletions Src/CrispyWaffle/CrispyWaffle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
<PackageReference Include="System.Text.Json" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="SonarAnalyzer.CSharp" Version="9.19.0.84025" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions Src/CrispyWaffle/Extensions/ConversionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public static int ToModule10(this string input)
var number = Regex.Replace(
input,
"[^0-9]",
"",
string.Empty,
RegexOptions.Compiled,
TimeSpan.FromSeconds(0.5)
);
Expand Down Expand Up @@ -422,7 +422,7 @@ public static int ToModule10(this string input)
}

/// <summary>
/// The ordinal suffix
/// The ordinal suffix.
/// </summary>
private static readonly Dictionary<int, string> _ordinalSuffix = new Dictionary<int, string>
{
Expand All @@ -440,7 +440,7 @@ public static string ToOrdinal(this long number)
{
if (number < 0)
{
return number.ToString();
return number.ToString(CultureInfo.CurrentCulture);
}

var rem = number % 100;
Expand Down Expand Up @@ -510,7 +510,7 @@ public static string FormatBrazilianZipCode(this string zipCode)
/// <summary>
/// Deeps the clone.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type parameter.</typeparam>
/// <param name="instance">The instance.</param>
/// <param name="useNonPublic">if set to <c>true</c> [use non public].</param>
/// <returns>T.</returns>
Expand Down Expand Up @@ -541,7 +541,7 @@ public static T DeepClone<T>(this T instance, bool useNonPublic = true)
/// <summary>
/// Parses the parameters.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T">The type parameter.</typeparam>
/// <param name="instance">The instance.</param>
/// <param name="useNonPublic">if set to <c>true</c> [use non public].</param>
/// <param name="type">The type.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override void Serialize<T>(T deserialized, out Stream stream)
stream = new MemoryStream();

var ns = new XmlSerializerNamespaces();
ns.Add("", "");
ns.Add(string.Empty, string.Empty);

var xmlConfig = new XmlWriterSettings
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/CrispyWaffle.Tests/CrispyWaffle.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
Expand Down

0 comments on commit 5c38c07

Please sign in to comment.