Reduce method and constructor parameters to fix SonarQube violations - #1808
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZkoVAEhIsbR56mqmhML for java:S107 rule - AZkoVAEhIsbR56mqmhMM for java:S107 rule - AZkoU_-OIsbR56mqmhLn for java:S107 rule - AZkoVAEhIsbR56mqmhMK for java:S107 rule - AZkoU_-OIsbR56mqmhLm for java:S107 rule Generated by SonarQube Agent (task: 873984c4-dd4f-419d-b999-651d482614f4)
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes 5 MAJOR SonarQube issues (java:S107) by reducing parameter counts in TreeFactory and UseStatementTreeImpl classes. The changes refactor methods to use tuple parameters and helper records (GroupPrefix, FunctionExpressionHeader) to keep parameter counts at or below the 7-parameter threshold, improving code maintainability and compliance with SonarQube standards.
View Project in SonarCloud
Fixed Issues
java:S107 - Method has 8 parameters, which is greater than 7 authorized. • MAJOR • View issue
Location:
php:php-frontend/src/main/java/org/sonar/php/parser/TreeFactory.java:1669Why is this an issue?
Methods with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their position.
What changed
Combines the DOUBLEARROW token and EXPRESSION into a single tuple parameter using f.newTuple(), reducing the number of arguments passed to the arrowFunctionExpression method from 8 to 7. This fixes the too-many-parameters code smell on the arrowFunctionExpression method at line 1669.
java:S107 - Constructor has 9 parameters, which is greater than 7 authorized. • MAJOR • View issue
Location:
php:php-frontend/src/main/java/org/sonar/php/tree/impl/statement/UseStatementTreeImpl.java:44Why is this an issue?
Methods with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their position.
What changed
Changes the fields
prefix,nsSeparatorToken, andopenCurlyBraceTokenfromfinalto non-final. This is necessary because these fields are no longer set via the constructor (which previously had 9 parameters). Instead, they are set after construction in thecreateGroupUseStatementfactory method, allowing the constructor's parameter count to be reduced below the threshold of 7.java:S107 - Method has 8 parameters, which is greater than 7 authorized. • MAJOR • View issue
Location:
php:php-frontend/src/main/java/org/sonar/php/tree/impl/statement/UseStatementTreeImpl.java:74Why is this an issue?
Methods with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their position.
What changed
Updates the
createUseStatementfactory method call to use the reduced constructor (5 parameters instead of 9, removing the null arguments for group-specific fields). Also introduces aGroupPrefixrecord that encapsulatesprefixandnsSeparatorTokeninto a single parameter, which helps reduce the parameter count of thecreateGroupUseStatementmethod from 8 to 7 (at the threshold).java:S107 - Method has 8 parameters, which is greater than 7 authorized. • MAJOR • View issue
Location:
php:php-frontend/src/main/java/org/sonar/php/parser/TreeFactory.java:1648Why is this an issue?
Methods with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their position.
What changed
Adds the import for FunctionExpressionHeader, a new helper type used to group the 'attribute groups' and 'static keyword' parameters of functionExpression into a single object. This supports reducing the parameter count of the functionExpression method from 8 to 7, fixing the too-many-parameters code smell on that method.
java:S107 - Method has 8 parameters, which is greater than 7 authorized. • MAJOR • View issue
Location:
php:php-frontend/src/main/java/org/sonar/php/parser/TreeFactory.java:1001Why is this an issue?
Methods with a long parameter list are difficult to use because maintainers must figure out the role of each parameter and keep track of their position.
What changed
Combines the ENDIF token and EOS into a single tuple parameter using f.newTuple(), reducing the number of arguments passed to the alternativeIfStatement method from 8 to 7. This fixes the too-many-parameters code smell on the alternativeIfStatement method at line 1001.
SonarQube Remediation Agent uses AI. Check for mistakes.