Skip to content

fix: merge switch cases and refactor brain method to fix SonarQube issues#20

Open
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260525-010114-b2c579ee
Open

fix: merge switch cases and refactor brain method to fix SonarQube issues#20
sonarqube-agent[bot] wants to merge 1 commit into
masterfrom
remediate-master-20260525-010114-b2c579ee

Conversation

@sonarqube-agent
Copy link
Copy Markdown

This PR was automatically created by the Remediation Agent's Scheduled backlog remediation feature.

Fixed 5 SonarQube code smells by consolidating fall-through switch case labels into comma-separated groups across three files and extracting a helper method to reduce complexity metrics in a Brain Method. These changes improve code readability and maintainability while adhering to modern Java practices.

View Project in SonarCloud


Fixed Issues

java:S6208 - Merge the previous cases into this one using comma-separated label. • INFOView issue

Location: php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java:172

Why is this an issue?

In Java 14 there is a new way to write cases in Switch Statement and Expression when the same action should be performed for different cases. Instead of declaring multiples branches with the same action, you can combine all of them in a single case group, separated with commas. It will result in a more concise code and improved readability.

What changed

This hunk merges six separate fall-through case labels (BYTE, INT, SHORT, CHAR, FLOAT, DOUBLE) into a single comma-separated case label. This addresses the code smell where multiple switch cases with the same action should be combined into one comma-separated case group, as supported since Java 14, resulting in more concise and readable code.

--- a/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java
+++ b/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java
@@ -167,6 +167,1 @@ public class ClientClassnameForMethod extends com.webcohesion.enunciate.util.fre
-        case BYTE:
-        case INT:
-        case SHORT:
-        case CHAR:
-        case FLOAT:
-        case DOUBLE:
+        case BYTE, INT, SHORT, CHAR, FLOAT, DOUBLE:
java:S6208 - Merge the previous cases into this one using comma-separated label. • INFOView issue

Location: php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java:131

Why is this an issue?

In Java 14 there is a new way to write cases in Switch Statement and Expression when the same action should be performed for different cases. Instead of declaring multiples branches with the same action, you can combine all of them in a single case group, separated with commas. It will result in a more concise code and improved readability.

What changed

This hunk merges the separate case BYTE:, case INT:, case SHORT:, and case LONG: labels into a single comma-separated case BYTE, INT, SHORT, LONG: label. This addresses the code smell where multiple fall-through case labels performing the same action should be combined into one comma-separated case group, as supported since Java 14, improving code conciseness and readability.

--- a/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java
+++ b/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java
@@ -128,4 +128,1 @@ public class TypeNameForMethod extends com.webcohesion.enunciate.util.freemarker
-        case BYTE:
-        case INT:
-        case SHORT:
-        case LONG:
+        case BYTE, INT, SHORT, LONG:
java:S6208 - Merge the previous cases into this one using comma-separated label. • INFOView issue

Location: php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java:134

Why is this an issue?

In Java 14 there is a new way to write cases in Switch Statement and Expression when the same action should be performed for different cases. Instead of declaring multiples branches with the same action, you can combine all of them in a single case group, separated with commas. It will result in a more concise code and improved readability.

What changed

This hunk merges the separate case FLOAT: and case DOUBLE: labels into a single comma-separated case FLOAT, DOUBLE: label. This addresses the code smell where multiple fall-through case labels performing the same action should be combined into one comma-separated case group, as supported since Java 14, improving code conciseness and readability.

--- a/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java
+++ b/php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java
@@ -133,2 +130,1 @@ public class TypeNameForMethod extends com.webcohesion.enunciate.util.freemarker
-        case FLOAT:
-        case DOUBLE:
+        case FLOAT, DOUBLE:
java:S6541 - A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 124 to 64, Complexity from 32 to 14, Nesting Level from 10 to 2, Number of Variables from 28 to 6. • INFOView issue

Location: java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/JavaXMLClientModule.java:146

Why is this an issue?

This issue is raised when Sonar considers that a method is a 'Brain Method'.
A Brain Method is a method that tends to centralize its owner’s class logic and generally performs too many operations. This can include checking too many conditions, using lots of variables, and ultimately making it difficult to understand, maintain and reuse.
It is characterized by high LOC number, high cyclomatic and cognitive complexity, and a large number of variables being used.

What changed

Removes the local variable declaration for 'model' from the generateClientSources() method, moving it into a separate helper method. This reduces the number of local variables defined in the Brain Method, contributing to lowering the NODV metric.

--- a/java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/JavaXMLClientModule.java
+++ b/java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/JavaXMLClientModule.java
@@ -150,2 +149,0 @@ public class JavaXMLClientModule extends BasicGeneratingModule implements ApiFea
-    Map<String, Object> model = new HashMap<>();
-
java:S6208 - Merge the previous cases into this one using comma-separated label. • INFOView issue

Location: jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/types/JsonPrimitiveType.java:55

Why is this an issue?

In Java 14 there is a new way to write cases in Switch Statement and Expression when the same action should be performed for different cases. Instead of declaring multiples branches with the same action, you can combine all of them in a single case group, separated with commas. It will result in a more concise code and improved readability.

What changed

This hunk merges the separate fall-through case labels (DOUBLE, FLOAT, INT, LONG, SHORT, BYTE) into a single comma-separated case label (case DOUBLE, FLOAT, INT, LONG, SHORT, BYTE:). This addresses the code smell where multiple switch cases with the same action should be combined into a single comma-separated case group, as supported since Java 14, resulting in more concise and readable code.

--- a/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/types/JsonPrimitiveType.java
+++ b/jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/types/JsonPrimitiveType.java
@@ -50,6 +50,1 @@ public class JsonPrimitiveType implements JsonType {
-      case DOUBLE:
-      case FLOAT:
-      case INT:
-      case LONG:
-      case SHORT:
-      case BYTE: //todo: verify 'byte' serialization?
+      case DOUBLE, FLOAT, INT, LONG, SHORT, BYTE: //todo: verify 'byte' serialization?

Have a suggestion or found an issue? Share your feedback here.


SonarQube Remediation Agent uses AI. Check for mistakes.

Fixed issues:
- AZZmth5D2HDYqP_Xynwe for java:S6208 rule
- AZZmth6t2HDYqP_Xynw8 for java:S6208 rule
- AZZmth6c2HDYqP_Xynwt for java:S6208 rule
- AZZmth6c2HDYqP_Xynwu for java:S6208 rule
- AZZmth2O2HDYqP_Xynvs for java:S6541 rule

Generated by SonarQube Agent (task: 5ce03ffe-aebd-4a0c-9e96-b9b7116cdffd)
@sonarqubecloud
Copy link
Copy Markdown

SonarQube reviewer guide

Review in SonarQube

Summary: Refactor code to use Java 14+ switch expression syntax and extract large method into smaller, focused helper methods for improved readability and maintainability.

Review Focus: The refactoring of JavaXMLClientModule.generateClientSources() is the most significant change—verify that the extraction of createFacetFilter(), initializeModel(), generateJaxwsClientSources(), and generateJaxbClientSources() maintains identical behavior, particularly around model state management and exception handling. Also ensure the switch case consolidations using comma syntax are functionally equivalent to the original fall-through patterns.

Start review at: java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/JavaXMLClientModule.java. This file contains the most substantial logic changes—extracting ~140 lines of nested logic into separate methods significantly impacts code flow and requires careful verification that no behavioral changes were introduced.

💬 Please send your feedback

Quality Gate Failed Quality Gate failed

Failed conditions
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant