< Summary

Information
Class: Allyaria.Theming.Contracts.StyleValueBase
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Contracts/StyleValueBase.cs
Line coverage
100%
Covered lines: 10
Uncovered lines: 0
Coverable lines: 10
Total lines: 58
Line coverage: 100%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_Value()100%11100%
TryValidateInput(...)50%44100%
ValidateInput(...)100%11100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Contracts/StyleValueBase.cs

#LineLine coverage
 1namespace Allyaria.Theming.Contracts;
 2
 3/// <summary>
 4/// Serves as the abstract base class for all style value types within the Allyaria theming system. Implements
 5/// <see cref="IStyleValue" /> and provides common validation and normalization behavior for CSS-compatible string value
 6/// </summary>
 7public abstract record StyleValueBase : IStyleValue
 8{
 9    /// <summary>
 10    /// Initializes a new instance of the <see cref="StyleValueBase" /> record with the specified string value.
 11    /// </summary>
 12    /// <param name="value">
 13    /// The CSS-compatible string value to assign. The value is automatically validated and trimmed during initializatio
 14    /// </param>
 15    /// <exception cref="AryArgumentException">
 16    /// Thrown when the provided <paramref name="value" /> contains invalid or control
 17    /// characters.
 18    /// </exception>
 3996219    protected StyleValueBase(string value) => Value = ValidateInput(value: value);
 20
 21    /// <summary>Gets the validated and normalized string value associated with this style instance.</summary>
 3851622    public string Value { get; }
 23
 24    /// <summary>Attempts to validate and normalize a string input for use as a CSS-compatible value.</summary>
 25    /// <param name="value">The input string to validate.</param>
 26    /// <param name="result">
 27    /// When this method returns, contains the trimmed version of the input string if validation succeeds, or an empty s
 28    /// if the input was <see langword="null" />.
 29    /// </param>
 30    /// <returns>
 31    /// <see langword="true" /> if the input contains no invalid control characters and is suitable for use as a style v
 32    /// otherwise, <see langword="false" />.
 33    /// </returns>
 34    private static bool TryValidateInput(string? value, out string result)
 35    {
 1998136        result = value?.Trim() ?? string.Empty;
 37
 19426338        return !result.Any(predicate: static c => char.IsControl(c: c));
 39    }
 40
 41    /// <summary>Validates and normalizes a string input, ensuring it is safe and CSS-compatible.</summary>
 42    /// <param name="value">The input string to validate and normalize.</param>
 43    /// <returns>The trimmed version of the input string if validation succeeds.</returns>
 44    /// <exception cref="AryArgumentException">
 45    /// Thrown when the provided <paramref name="value" /> contains control characters or is otherwise deemed invalid fo
 46    /// as a CSS value.
 47    /// </exception>
 48    private static string ValidateInput(string? value)
 49    {
 1998150        AryGuard.Check(
 1998151            condition: TryValidateInput(value: value, result: out var result),
 1998152            argName: nameof(value),
 1998153            message: $"Invalid value: {value}"
 1998154        );
 55
 1997956        return result;
 57    }
 58}