fix(query): modernize CalculationFilterGroup and adjust IsValid behavior
SonarQube Analysis / sonarqube (pull_request) Successful in 3m9s
SonarQube Analysis / sonarqube (pull_request) Successful in 3m9s
Refactors the `CalculationFilterGroup` class to utilize C# primary constructors and property initializers, improving conciseness and readability. The `IsValid()` method's logic is updated. Previously, it returned true if *any* filter in the group was valid. Now, it returns true only if *all* filters are valid, and an empty filter group is considered valid. This adjustment clarifies the group's validity criteria, aligning with common interpretations for `All` operations and addressing related technical debt.
This commit is contained in:
@@ -23,7 +23,9 @@
|
||||
"Bash(Get-ChildItem src/Strata.SqlTools.SqlServer/ExpressionFactory/Query/*.cs)",
|
||||
"Bash(Measure-Object)",
|
||||
"Bash(Select-Object -ExpandProperty Count)",
|
||||
"PowerShell(dotnet build *)"
|
||||
"PowerShell(dotnet build *)",
|
||||
"Bash(Get-ChildItem src/Strata.SqlTools.Query/*.cs)",
|
||||
"Bash(Select-String -Pattern '^namespace ')"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,24 +2,16 @@ using System.Text.Json.Serialization;
|
||||
|
||||
namespace Strata.SqlTools.Query;
|
||||
|
||||
public class CalculationFilterGroup
|
||||
[method: JsonConstructor]
|
||||
public class CalculationFilterGroup(IEnumerable<CalculationFilter> filters, LogicalOperator logicalOperator)
|
||||
{
|
||||
// Hereditary logical operation applied to all Filters
|
||||
public LogicalOperator LogicalOperator { get; set; }
|
||||
public LogicalOperator LogicalOperator { get; set; } = logicalOperator;
|
||||
|
||||
public IEnumerable<CalculationFilter> Filters { get; set; }
|
||||
public IEnumerable<CalculationFilter> Filters { get; set; } = filters;
|
||||
|
||||
public CalculationFilterGroup()
|
||||
public CalculationFilterGroup() : this([], LogicalOperator.And)
|
||||
{
|
||||
LogicalOperator = LogicalOperator.And;
|
||||
Filters = new List<CalculationFilter>();
|
||||
}
|
||||
|
||||
[JsonConstructor]
|
||||
public CalculationFilterGroup(IEnumerable<CalculationFilter> filters, LogicalOperator logicalOperator)
|
||||
{
|
||||
Filters = filters;
|
||||
LogicalOperator = logicalOperator;
|
||||
}
|
||||
|
||||
public IEnumerable<CalculationFilter> GetValidFilters()
|
||||
@@ -29,6 +21,6 @@ public class CalculationFilterGroup
|
||||
|
||||
public bool IsValid()
|
||||
{
|
||||
return Filters != null && Filters.Any(x => x.IsValid());
|
||||
return Filters.All(x => x.IsValid());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user