Skip to content

Commit

Permalink
SONARPHP-977 No secondary on the declaration when the caught class is…
Browse files Browse the repository at this point in the history
… a duplicate (#599)
  • Loading branch information
pynicolas authored Jul 24, 2020
1 parent b39af16 commit 4adfdca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.sonar.plugins.php.api.tree.statement.CatchBlockTree;
import org.sonar.plugins.php.api.tree.statement.TryStatementTree;
import org.sonar.plugins.php.api.visitors.PHPVisitorCheck;
import org.sonar.plugins.php.api.visitors.PreciseIssue;

@Rule(key = "S1045")
public class UnreachableCatchBlockCheck extends PHPVisitorCheck {
Expand Down Expand Up @@ -58,9 +59,11 @@ public void visitTryStatement(TryStatementTree tree) {
if (caughtSuperClasses.values().stream().allMatch(Optional::isPresent)) {
caughtInThisCatch.forEach((symbol, name) -> {
ClassSymbol superClass = caughtSuperClasses.get(symbol).get();
context().newIssue(this, name, MESSAGE)
.secondary(previouslyCaught.get(superClass), null)
.secondary(symbol.location(), null);
PreciseIssue issue = context().newIssue(this, name, MESSAGE)
.secondary(previouslyCaught.get(superClass), null);
if (symbol != superClass) {
issue.secondary(symbol.location(), null);
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ class A2 extends A {}

try {}
catch (A $e) {}
// ^>
catch (A $e) {} // Noncompliant
// ^

try {}
catch (A1 $e) {}
Expand Down

0 comments on commit 4adfdca

Please sign in to comment.