Skip to content

Reduce cyclomatic complexity of OnPost in Ciba/Consent.cshtml.cs#1049

Merged
StuartFerguson merged 2 commits intomasterfrom
copilot/codacy-issue-d9c3f423d4bb9476d626d1e156475960-redu
Mar 9, 2026
Merged

Reduce cyclomatic complexity of OnPost in Ciba/Consent.cshtml.cs#1049
StuartFerguson merged 2 commits intomasterfrom
copilot/codacy-issue-d9c3f423d4bb9476d626d1e156475960-redu

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

OnPost in Ciba/Consent.cshtml.cs had a cyclomatic complexity of 9, exceeding the Lizard/Codacy limit of 8 due to the chained if/else if/else button-selection branches combined with null-conditional operators.

Changes

  • Extracted HandleButtonClickAsync — moves the "no" / "yes" / default branching out of OnPost into a dedicated private method using a switch, reducing OnPost's complexity to ~4.
// Before — all inline in OnPost
if (Input?.Button == "no") {
    result = await HandleNoButtonClicked(request);
} else if (Input?.Button == "yes") {
    result = await HandleYesButtonClicked(request);
} else {
    ModelState.AddModelError("", ConsentOptions.InvalidSelectionErrorMessage);
}

// After — delegated to helper, matching pattern in Pages/Consent/Index.cshtml.cs
private async Task<CompleteBackchannelLoginRequest> HandleButtonClickAsync(BackchannelUserLoginRequest request)
{
    switch (Input?.Button)
    {
        case "no":    return await HandleNoButtonClicked(request);
        case "yes":   return await HandleYesButtonClicked(request);
        default:
            ModelState.AddModelError("", ConsentOptions.InvalidSelectionErrorMessage);
            return null;
    }
}

This aligns with the pattern already used in Pages/Consent/Index.cshtml.cs (HandleConsentAsync). No behavioural changes.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet build SecurityService.UserInterface/SecurityService.UserInterface.csproj (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/SecurityService/SecurityService/SecurityService.sln --packages /tmp/codeql-scratch-89cd281515db216c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-89cd281515db216c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-89cd281515db216c/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Codacy] Warning issue(s) in SecurityService.UserInterface/Pages/Ciba/Consent.cshtml.cs</issue_title>
<issue_description>Codacy detected 1 occurrence(s) of rule Lizard_ccn-medium:

  • Warning at SecurityService.UserInterface/Pages/Ciba/Consent.cshtml.cs:94 → Method Consent::OnPost has a cyclomatic complexity of 9 (limit is 8)

See full details in Codacy Report

Unique ID: codacy-issue-d9c3f423d4bb9476d626d1e156475960</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cyclomatic complexity in Consent.OnPost method Reduce cyclomatic complexity of OnPost in Ciba/Consent.cshtml.cs Mar 9, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review March 9, 2026 11:16
@StuartFerguson StuartFerguson merged commit aae4c63 into master Mar 9, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Codacy] Warning issue(s) in SecurityService.UserInterface/Pages/Ciba/Consent.cshtml.cs

2 participants