Skip to content

core: fix MA0140 duplicate branches in ServiceProviderFactory#785

Open
berezovskyi wants to merge 1 commit into
mainfrom
fix-ma0140-serviceproviderfactory-17216203223603717034
Open

core: fix MA0140 duplicate branches in ServiceProviderFactory#785
berezovskyi wants to merge 1 commit into
mainfrom
fix-ma0140-serviceproviderfactory-17216203223603717034

Conversation

@berezovskyi

@berezovskyi berezovskyi commented Jun 6, 2026

Copy link
Copy Markdown
Member

Refactor ResolvePathParameters to resolve MA0140 warning

Extracted the common returnUri assignment out of the if and else branches in the ServiceProviderFactory.ResolvePathParameters method. The redundant conditional structure generated an MA0140 warning due to identical code in both branches.
Preserved the TODO comment structure.
Ran dotnet format style on the solution.


PR created automatically by Jules for task 17216203223603717034 started by @berezovskyi

Summary by CodeRabbit

  • Refactor
    • Simplified internal code logic for improved maintainability.

Extracted the common `returnUri` assignment out of the `if` and `else` branches in the `ServiceProviderFactory.ResolvePathParameters` method. The redundant conditional structure generated an MA0140 warning due to identical code in both branches.
Preserved the TODO comment structure.
Ran `dotnet format style` on the solution.

Co-authored-by: berezovskyi <64734+berezovskyi@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Looking for one thing? Review this PR in Change Stack to search files, summaries, diffs, and code without losing your place.

Review Change Stack

Walkthrough

This PR refactors the conditional logic in ServiceProviderFactory.ResolvePathParameters by consolidating the fallback URI assignment. The method no longer duplicates the fallback case in an else branch, instead assigning the URI once unconditionally after the parameter-resolution check. The unresolved templating TODO remains intact.

Changes

Path Resolution Simplification

Layer / File(s) Summary
Simplified path parameter fallback assignment
OSLC4Net_SDK/OSLC4Net.Core/Model/ServiceProviderFactory.cs
ResolvePathParameters removes the else branch and consolidates fallback returnUri assignment to execute unconditionally after the pathParameterValues check, eliminating code duplication while preserving the existing fallback behavior.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A simpler path the code now treads,
No branching where one code-path threads,
One fallback assignment, clean and bright,
Control flow flows with less to fight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main change: fixing MA0140 duplicate code branches in ServiceProviderFactory by refactoring conditional logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-ma0140-serviceproviderfactory-17216203223603717034

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-code-quality

Copy link
Copy Markdown
Contributor

Code Coverage Overview

Languages: C#

C# / dotnet/cobertura

The overall coverage remains at 55%, unchanged from the branch.


Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
OSLC4Net_SDK/OSLC4Net.Core/Model/ServiceProviderFactory.cs (1)

368-381: ⚡ Quick win

Good refactoring to eliminate duplication, but update the comment to reflect current behavior.

The MA0140 fix correctly consolidates the duplicate assignment. However, the comment on line 380 is now misleading—it describes this as "Fallback or no parameters supplied," but since templated path resolution is not yet implemented (the TODO block doesn't assign returnUri), this code always executes regardless of whether parameters are supplied.

♻️ Proposed fix to clarify the comment
-        // Fallback or no parameters supplied - assume `@Path` not templated
+        // Current implementation: templated path resolution not yet supported - assume `@Path` not templated
         returnUri = basePath + "/" + pathAttribute;

Alternatively, consider simplifying the method structure since the conditional currently adds no functional value:

 private static string ResolvePathParameters(string basePath, string pathAttribute,
     Dictionary<string, object> pathParameterValues)
 {
-    string returnUri;
-
-    //Build the path from the `@Path` template + map of parameter value replacements
-    if (pathParameterValues != null && pathParameterValues.Count > 0)
-    {
-        /* TODO - not supported yet
-        UriBuilder builder = UriBuilder.fromUri(basePath);
-        URI resolvedUri = builder.path(pathAttribute).buildFromMap(pathParameterValues);
-        if (resolvedUri != null)
-        {
-            returnUri = resolvedUri.tostring();
-        }
-    */
-    }
-
-    // Fallback or no parameters supplied - assume `@Path` not templated
-    returnUri = basePath + "/" + pathAttribute;
-
-    return returnUri;
+    /* TODO: Build the path from the `@Path` template + map of parameter value replacements
+     * Currently not supported - templated path resolution would use pathParameterValues here
+     * Example: UriBuilder.fromUri(basePath).path(pathAttribute).buildFromMap(pathParameterValues)
+     */
+    
+    // Current implementation: assume `@Path` is not templated
+    return basePath + "/" + pathAttribute;
 }

As per coding guidelines, this aligns with Building Maintainable Software principle "Write Simple Units of Code" by removing the conditional structure that adds no current value while preserving the TODO for future implementation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@OSLC4Net_SDK/OSLC4Net.Core/Model/ServiceProviderFactory.cs` around lines 368
- 381, The if (pathParameterValues != null && pathParameterValues.Count > 0)
block currently has no effect because templated path resolution is not
implemented; update the code by removing that no-op conditional (or at minimum
collapsing it) and replace the misleading comment with a clear note that
templated `@Path` resolution is not yet supported and the method always falls back
to constructing returnUri as basePath + "/" + pathAttribute; reference the
symbols pathParameterValues, returnUri, pathAttribute and basePath in your
change and keep the existing TODO about adding templated resolution later.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@OSLC4Net_SDK/OSLC4Net.Core/Model/ServiceProviderFactory.cs`:
- Around line 368-381: The if (pathParameterValues != null &&
pathParameterValues.Count > 0) block currently has no effect because templated
path resolution is not implemented; update the code by removing that no-op
conditional (or at minimum collapsing it) and replace the misleading comment
with a clear note that templated `@Path` resolution is not yet supported and the
method always falls back to constructing returnUri as basePath + "/" +
pathAttribute; reference the symbols pathParameterValues, returnUri,
pathAttribute and basePath in your change and keep the existing TODO about
adding templated resolution later.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0ccc958b-dbf3-4453-8f6e-8a23c0618258

📥 Commits

Reviewing files that changed from the base of the PR and between 923ed12 and 322c914.

📒 Files selected for processing (1)
  • OSLC4Net_SDK/OSLC4Net.Core/Model/ServiceProviderFactory.cs

@codecov

codecov Bot commented Jun 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.27%. Comparing base (923ed12) to head (322c914).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #785   +/-   ##
=======================================
  Coverage   51.26%   51.27%           
=======================================
  Files         174      174           
  Lines       10281    10280    -1     
  Branches     1057     1057           
=======================================
  Hits         5271     5271           
+ Misses       4750     4749    -1     
  Partials      260      260           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@berezovskyi berezovskyi changed the title Fix MA0140: identical code in if/else branches in ServiceProviderFactory core: fix MA0140 duplicate branches in ServiceProviderFactory Jun 6, 2026
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.

1 participant