SONARPHP-1817 fix: resolve 5 SonarQube issues in test files#1699
SONARPHP-1817 fix: resolve 5 SonarQube issues in test files#1699sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AZkoVASCIsbR56mqmhM9 for java:S5786 rule - AZkoU-_5IsbR56mqmhGg for java:S1130 rule - AZkoVASeIsbR56mqmhNA for java:S5786 rule - AZkoVAR0IsbR56mqmhM8 for java:S5786 rule - AZkoVASSIsbR56mqmhM_ for java:S5786 rule Generated by SonarQube Agent (task: f1414618-3b8e-4d49-ba83-d56de847243b)
Summary
This PR removes 5 SonarQube code smells from test files: 1 instance of java:S1130 (FileUploadsCheckTest.java:33)
4 instances of java:S5786 (4 test files)
All changes are in test files only. No behavior changes—purely stylistic cleanup to align with JUnit5 conventions and improve code readability. What reviewers should knowFiles affected:
Safe to approve:
Review notes:
|
There was a problem hiding this comment.
LGTM! ✅
Clean, targeted cleanup — all 5 changes are correct and each fix is well-scoped. The throws IOException kept on SymbolScannerTest.init() is intentional and correct (Files.createTempDirectory is a real checked-exception caller).
One thing worth a follow-up: FileUploadsCheckTest.fileIssue() (line 38, outside the diff) still carries throws Exception even though it calls the same PhpIniCheckTestUtils.check() overload, which handles IOException internally and never propagates a checked exception to callers. Since SonarQube flagged lineIssues() on line 33 for the same pattern, fileIssue() is likely a missed companion fix. It won't cause a test failure, but it leaves the class in an inconsistent state — worth cleaning up in a follow-on commit or as part of this PR.
|





Removed unnecessary 'throws Exception' declaration from a test method and removed 'public' modifiers from four JUnit5 lifecycle methods. These changes follow JUnit5 conventions which do not require public visibility and improve code clarity by ensuring method signatures accurately reflect their actual behavior.
View Project in SonarCloud
Fixed Issues
java:S1130 - Remove the declaration of thrown exception 'java.lang.Exception', as it cannot be thrown from method's body. • MINOR • View issue
Location:
php:php-checks/src/test/java/org/sonar/php/checks/phpini/FileUploadsCheckTest.java:33Why is this an issue?
Superfluous exceptions within
throwsclauses have negative effects on the readability and maintainability of the code. An exception in athrowsclause is superfluous if it is:What changed
Removes the superfluous 'throws Exception' declaration from the 'lineIssues()' method signature. The method body does not actually throw any checked exception of type 'java.lang.Exception', so declaring it in the throws clause was unnecessary and reduced code readability. By removing it, the method signature now accurately reflects the exceptions that can be thrown.
java:S5786 - Remove this 'public' modifier. • INFO • View issue
Location:
php:sonar-php-plugin/src/test/java/org/sonar/plugins/php/SymbolScannerTest.java:58Why is this an issue?
JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be
public. Test classes and methods can have any visibility exceptprivate. It is however recommended to use the default package visibility to improve readability.What changed
This hunk removes the 'public' modifier from the 'init()' lifecycle method in the JUnit5 test class 'SymbolScannerTest'. JUnit5 test classes and methods should use default package visibility rather than 'public', as JUnit5 does not require public visibility. Changing 'public void init()' to 'void init()' follows the JUnit5 convention and resolves the code smell about unnecessary 'public' modifiers on test lifecycle methods.
java:S5786 - Remove this 'public' modifier. • INFO • View issue
Location:
php:sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/phpunit/TestFileReportTest.java:49Why is this an issue?
JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be
public. Test classes and methods can have any visibility exceptprivate. It is however recommended to use the default package visibility to improve readability.What changed
This hunk removes the 'public' modifier from the setUp() lifecycle method in the JUnit5 test class TestFileReportTest, changing it from 'public void setUp()' to 'void setUp()'. JUnit5 test classes and lifecycle methods should use default package visibility rather than 'public', as recommended by the JUnit5 User Guide. This directly addresses the code smell about unnecessary 'public' modifiers on JUnit5 lifecycle methods.
java:S5786 - Remove this 'public' modifier. • INFO • View issue
Location:
php:sonar-php-plugin/src/test/java/org/sonar/plugins/php/reports/ExternalReportFileHandlerTest.java:39Why is this an issue?
JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be
public. Test classes and methods can have any visibility exceptprivate. It is however recommended to use the default package visibility to improve readability.What changed
This hunk removes the 'public' modifier from the 'setup()' lifecycle method in the JUnit5 test class 'ExternalReportFileHandlerTest'. JUnit5 test classes and methods should use default package visibility rather than 'public', as JUnit5 does not require public visibility. Changing 'public void setup()' to 'void setup()' follows the JUnit5 convention and resolves the code smell about unnecessary 'public' modifiers on test lifecycle methods.
java:S5786 - Remove this 'public' modifier. • INFO • View issue
Location:
php:sonar-php-plugin/src/test/java/org/sonar/plugins/php/PhpPluginTest.java:35Why is this an issue?
JUnit5 is more tolerant regarding the visibility of test classes and methods than JUnit4, which required everything to be
public. Test classes and methods can have any visibility exceptprivate. It is however recommended to use the default package visibility to improve readability.What changed
This hunk removes the 'public' modifier from the setUp() lifecycle method in the JUnit5 test class PhpPluginTest. JUnit5 recommends using default package visibility for test classes, test methods, and lifecycle methods. By changing 'public void setUp()' to 'void setUp()', the code follows JUnit5 conventions and resolves the code smell about unnecessary 'public' modifiers on JUnit5 lifecycle methods.
SonarQube Remediation Agent uses AI. Check for mistakes.