< Summary - Kestrun β€” Combined Coverage

Information
Class: Kestrun.OpenApi.FunctionInfoExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/OpenApi/FunctionInfoExtensions.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
75%
Covered lines: 18
Uncovered lines: 6
Coverable lines: 24
Total lines: 55
Line coverage: 75%
Branch coverage
62%
Covered branches: 15
Total branches: 24
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/15/2025 - 18:44:50 Line coverage: 75% (18/24) Branch coverage: 62.5% (15/24) Total lines: 55 Tag: Kestrun/Kestrun@6b9e56ea2de904fc3597033ef0f9bc7839d5d618 12/15/2025 - 18:44:50 Line coverage: 75% (18/24) Branch coverage: 62.5% (15/24) Total lines: 55 Tag: Kestrun/Kestrun@6b9e56ea2de904fc3597033ef0f9bc7839d5d618

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetDefaultParameterValue(...)62.5%332475%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/OpenApi/FunctionInfoExtensions.cs

#LineLine coverage
 1using System.Management.Automation;
 2using System.Management.Automation.Language;
 3
 4namespace Kestrun.OpenApi;
 5
 6/// <summary>
 7/// Extension methods for FunctionInfo.
 8/// </summary>
 9public static class FunctionInfoExtensions
 10{
 11    /// <summary>
 12    /// Gets the default value of a parameter in a FunctionInfo, if it has one.
 13    /// </summary>
 14    /// <param name="func">The FunctionInfo to inspect.</param>
 15    /// <param name="paramName">The name of the parameter.</param>
 16    /// <returns>The default value of the parameter, or null if none exists.</returns>
 17    public static object? GetDefaultParameterValue(this FunctionInfo func, string paramName)
 18    {
 1719        if (func.ScriptBlock?.Ast is not FunctionDefinitionAst fa)
 20        {
 021            return null;
 22        }
 1723        if (fa.Body is not ScriptBlockAst scriptAst)
 24        {
 025            return null;
 26        }
 27        // Find the ParameterAst for the given parameter name
 1728        var paramAst = scriptAst.ParamBlock?.Parameters
 1729            .OfType<ParameterAst>()
 1730            .FirstOrDefault(p =>
 3731                p.Name?.VariablePath?.UserPath != null &&
 3732                p.Name.VariablePath.UserPath.Equals(paramName, StringComparison.OrdinalIgnoreCase));
 33
 1734        if (paramAst?.DefaultValue is null)
 35        {
 236            return null; // no default
 37        }
 38
 1539        var defaultExpr = paramAst.DefaultValue;
 40
 41        // Common cases: constant or array of constants
 1542        return defaultExpr switch
 1543        {
 944            ConstantExpressionAst c => c.Value,
 1545
 046            ArrayLiteralAst a when a.Elements.All(e => e is ConstantExpressionAst) =>
 047                a.Elements.Cast<ConstantExpressionAst>()
 048                    .Select(e => e.Value)
 049                    .ToArray(),
 1550
 1551            // Fallback β€“ return the textual expression if it’s something more complex
 652            _ => defaultExpr.Extent.Text
 1553        };
 54    }
 55}