fix: merge switch cases and refactor brain method to fix SonarQube issues#20
fix: merge switch cases and refactor brain method to fix SonarQube issues#20sonarqube-agent[bot] wants to merge 1 commit into
Conversation
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)
SonarQube reviewer guideSummary: 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 Start review at:
|





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. • INFO • View issue
Location:
php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/ClientClassnameForMethod.java:172Why 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.
java:S6208 - Merge the previous cases into this one using comma-separated label. • INFO • View issue
Location:
php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java:131Why 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:, andcase LONG:labels into a single comma-separatedcase 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.java:S6208 - Merge the previous cases into this one using comma-separated label. • INFO • View issue
Location:
php-xml-client/src/main/java/com/webcohesion/enunciate/modules/php_xml_client/TypeNameForMethod.java:134Why 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:andcase DOUBLE:labels into a single comma-separatedcase 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.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. • INFO • View issue
Location:
java-xml-client/src/main/java/com/webcohesion/enunciate/modules/java_xml_client/JavaXMLClientModule.java:146Why 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.
java:S6208 - Merge the previous cases into this one using comma-separated label. • INFO • View issue
Location:
jackson/src/main/java/com/webcohesion/enunciate/modules/jackson/model/types/JsonPrimitiveType.java:55Why 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.SonarQube Remediation Agent uses AI. Check for mistakes.