< Summary

Information
Class: Fluorite.Strainer.Services.Sorting.SortTermParser
Assembly: Fluorite.Strainer
File(s): /builds/fluorite/strainer/src/Strainer/Services/Sorting/SortTermParser.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 61
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetParsedTerms(...)100%1212100%

File(s)

/builds/fluorite/strainer/src/Strainer/Services/Sorting/SortTermParser.cs

#LineLine coverage
 1using Fluorite.Strainer.Models.Sorting;
 2using Fluorite.Strainer.Models.Sorting.Terms;
 3
 4namespace Fluorite.Strainer.Services.Sorting;
 5
 6public class SortTermParser : ISortTermParser
 7{
 8    private readonly ISortingWayFormatter _formatter;
 9    private readonly IStrainerOptionsProvider _strainerOptionsProvider;
 10    private readonly ISortTermValueParser _sortTermValueParser;
 11
 612    public SortTermParser(
 613        ISortingWayFormatter formatter,
 614        IStrainerOptionsProvider strainerOptionsProvider,
 615        ISortTermValueParser sortTermValueParser)
 16    {
 617        _formatter = Guard.Against.Null(formatter);
 618        _strainerOptionsProvider = Guard.Against.Null(strainerOptionsProvider);
 619        _sortTermValueParser = Guard.Against.Null(sortTermValueParser);
 620    }
 21
 22    public IList<ISortTerm> GetParsedTerms(string? input)
 23    {
 524        if (string.IsNullOrEmpty(input))
 25        {
 226            return new List<ISortTerm>();
 27        }
 28
 329        var values = _sortTermValueParser.GetParsedValues(input);
 330        if (!values.Any())
 31        {
 132            return new List<ISortTerm>();
 33        }
 34
 235        var terms = new List<ISortTerm>();
 236        var options = _strainerOptionsProvider.GetStrainerOptions();
 37
 838        foreach (var value in values)
 39        {
 240            if (string.IsNullOrWhiteSpace(value))
 41            {
 42                continue;
 43            }
 44
 245            var sortingWay = _formatter.GetSortingWay(value) ?? options.DefaultSortingWay;
 246            var name = _formatter.Unformat(value, sortingWay);
 247            var sortTerm = new SortTerm(name)
 248            {
 249                Input = value,
 250                IsDescending = sortingWay == SortingWay.Descending,
 251            };
 52
 253            if (!terms.Any(s => s.Name == sortTerm.Name))
 54            {
 255                terms.Add(sortTerm);
 56            }
 57        }
 58
 259        return terms;
 60    }
 61}