< Summary

Information
Class: MyNet.Text.Redaction.FixedMaskTextRedactor
Assembly: MyNet.Text
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Redaction/FixedMaskTextRedactor.cs
Tag: 323_28699572109
Line coverage
83%
Covered lines: 10
Uncovered lines: 2
Coverable lines: 12
Total lines: 37
Line coverage: 83.3%
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
Apply(...)50%4483.33%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Text/Redaction/FixedMaskTextRedactor.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="FixedMaskTextRedactor.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Globalization;
 9
 10namespace MyNet.Text.Redaction;
 11
 12/// <summary>
 13/// Redacts text by masking the middle section.
 14/// </summary>
 15public sealed class FixedMaskTextRedactor(TextRedactionOptions options) : ITextRedactorTransform
 16{
 17    /// <inheritdoc/>
 18    public string Apply(string input, CultureInfo culture)
 19    {
 320        ArgumentNullException.ThrowIfNull(input);
 321        ArgumentNullException.ThrowIfNull(culture);
 22
 323        if (input.Length == 0)
 024            return input;
 25
 326        var visible = options.ShowStart + options.ShowEnd;
 327        if (visible >= input.Length)
 028            return input;
 29
 330        var maskedLength = input.Length - visible;
 331        return string.Concat(
 332            input.AsSpan(0, options.ShowStart),
 333            new string(options.MaskCharacter, maskedLength),
 334            input.AsSpan(input.Length - options.ShowEnd));
 35    }
 36}
 37