Skip to content

Reduce cyclomatic complexity of CreateConsentViewModel#1050

Merged
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-cyclomatic-complexity-issue
Mar 9, 2026
Merged

Reduce cyclomatic complexity of CreateConsentViewModel#1050
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-cyclomatic-complexity-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

CreateConsentViewModel in Pages/Consent/Index.cshtml.cs had a cyclomatic complexity of 14 against a limit of 8, caused by inline null-conditional chains, logical operators, and a foreach/if combination all within a single method.

Changes

  • Extracted GetIdentityScopes — isolates identity resource scope mapping
  • Extracted GetApiScopes — isolates API scope mapping including resource indicators, parsed scope iteration, and offline access handling
  • Extracted IsScopeConsented — consolidates three separate inline consent-check expressions into a single reusable helper using the simplified pattern:
private bool IsScopeConsented(InputModel model, string scopeName)
{
    return model?.ScopesConsented?.Contains(scopeName) != false;
}

CreateConsentViewModel now delegates entirely to these helpers, reducing its complexity to ~1. Each extracted method stays well below the limit of 8.

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/Consent/Index.cshtml.cs</issue_title>
<issue_description>Codacy detected 1 occurrence(s) of rule Lizard_ccn-medium:

  • Warning at SecurityService.UserInterface/Pages/Consent/Index.cshtml.cs:162 → Method Index::CreateConsentViewModel has a cyclomatic complexity of 14 (limit is 8)

See full details in Codacy Report

Unique ID: codacy-issue-5e98864271937c16df58a9ec59f757b9</issue_description>

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


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…helper methods

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cyclomatic complexity in CreateConsentViewModel method Reduce cyclomatic complexity of CreateConsentViewModel Mar 9, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review March 9, 2026 11:31
@StuartFerguson StuartFerguson merged commit 2bd228b into master Mar 9, 2026
12 checks passed
@github-actions github-actions Bot deleted the copilot/fix-cyclomatic-complexity-issue branch May 9, 2026 02:47
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/Consent/Index.cshtml.cs

2 participants