From 2826c96f637f61860e11bc632416408da06893e0 Mon Sep 17 00:00:00 2001 From: Gonzalo Diaz Date: Wed, 4 Sep 2024 00:07:44 -0400 Subject: [PATCH] [REFACTOR] Codefactor issues, fixed. --- .../dictionaries_and_hashmaps/RansomNote.cs | 14 ++--- .../greedy_algorithms/LuckBalance.cs | 12 ++-- .../src/hackerrank/projecteuler/Euler003.cs | 2 +- algorithm_exercises_csharp_base/src/Logger.cs | 56 +++++++++---------- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.cs b/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.cs index 62d1c61..1d01115 100644 --- a/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.cs +++ b/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/dictionaries_and_hashmaps/RansomNote.cs @@ -5,17 +5,17 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit; using System.Diagnostics.CodeAnalysis; using System.Collections.Generic; -public class InvalidValueException : Exception +public class RansomNote { - // constructor for the InvalidAgeException class - public InvalidValueException(string msg) + public class InvalidValueException : Exception { - Console.WriteLine(msg); + // constructor for the InvalidAgeException class + public InvalidValueException(string msg) + { + Console.WriteLine(msg); + } } -} -public class RansomNote -{ [ExcludeFromCodeCoverage] protected RansomNote() { } diff --git a/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/greedy_algorithms/LuckBalance.cs b/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/greedy_algorithms/LuckBalance.cs index e86aa6f..1c02958 100644 --- a/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/greedy_algorithms/LuckBalance.cs +++ b/algorithm_exercises_csharp/src/hackerrank/interview_preparation_kit/greedy_algorithms/LuckBalance.cs @@ -4,14 +4,14 @@ namespace algorithm_exercises_csharp.hackerrank.interview_preparation_kit; using System.Diagnostics.CodeAnalysis; -public class Competition(int _luck, int _important) -{ - public int luck => _luck; - public int important => _important; -} - public class LuckBalance { + public class Competition(int _luck, int _important) + { + public int luck => _luck; + public int important => _important; + } + [ExcludeFromCodeCoverage] protected LuckBalance() { } diff --git a/algorithm_exercises_csharp/src/hackerrank/projecteuler/Euler003.cs b/algorithm_exercises_csharp/src/hackerrank/projecteuler/Euler003.cs index ea49c90..6f53516 100644 --- a/algorithm_exercises_csharp/src/hackerrank/projecteuler/Euler003.cs +++ b/algorithm_exercises_csharp/src/hackerrank/projecteuler/Euler003.cs @@ -22,7 +22,7 @@ protected Euler003() { } int i = 2; while (i <= Math.Sqrt(divisor)) { - if (0 == divisor % i) + if (divisor % i == 0) { divisor = divisor / i; max_prime_factor = divisor; diff --git a/algorithm_exercises_csharp_base/src/Logger.cs b/algorithm_exercises_csharp_base/src/Logger.cs index a061312..286dcdf 100644 --- a/algorithm_exercises_csharp_base/src/Logger.cs +++ b/algorithm_exercises_csharp_base/src/Logger.cs @@ -3,45 +3,45 @@ namespace algorithm_exercises_csharp; using Microsoft.Extensions.Logging; using System; -public sealed class LoggerSingleton +public static class Log { - private static readonly Lazy _instance = new(() => new LoggerSingleton()); - - public static LoggerSingleton Instance => _instance.Value; + sealed class LoggerSingleton + { + private static readonly Lazy _instance = new(() => new LoggerSingleton()); - public ILogger Logger { get; } + public static LoggerSingleton Instance => _instance.Value; - private LoggerSingleton() - { - // Read the LOG_LEVEL environment variable - var logLevelEnv = Environment.GetEnvironmentVariable("LOG_LEVEL") ?? "Information"; + public ILogger Logger { get; } - // Convert the environment variable value to LogLevel - if (!Enum.TryParse(logLevelEnv, ignoreCase: true, out var logLevel)) + private LoggerSingleton() { - logLevel = LogLevel.Information; // Set the minimum logging level - } + // Read the LOG_LEVEL environment variable + var logLevelEnv = Environment.GetEnvironmentVariable("LOG_LEVEL") ?? "Information"; - var loggerFactory = LoggerFactory.Create(builder => - { - builder - .AddConsole() - .SetMinimumLevel(logLevel); // set minimum logging level - }); + // Convert the environment variable value to LogLevel + if (!Enum.TryParse(logLevelEnv, ignoreCase: true, out var logLevel)) + { + logLevel = LogLevel.Information; // Set the minimum logging level + } - Logger = loggerFactory.CreateLogger("GlobalLogger"); + var loggerFactory = LoggerFactory.Create(builder => + { + builder + .AddConsole() + .SetMinimumLevel(logLevel); // set minimum logging level + }); - Logger.LogInformation("Initializing"); + Logger = loggerFactory.CreateLogger("GlobalLogger"); - Logger.LogInformation("Info level enabled"); - Logger.LogWarning("Warning level enabled"); - Logger.LogError("Error level enabled"); - Logger.LogDebug("Debug level enabled"); + Logger.LogInformation("Initializing"); + + Logger.LogInformation("Info level enabled"); + Logger.LogWarning("Warning level enabled"); + Logger.LogError("Error level enabled"); + Logger.LogDebug("Debug level enabled"); + } } -} -public static class Log -{ public static ILogger getLogger() { return LoggerSingleton.Instance.Logger;