Skip to content

Commit

Permalink
SonarCloud warnings corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
dedece35 committed Dec 16, 2024
1 parent 6e3ec82 commit 8c4c322
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ private void computeIfVariables(IfStatementTree pIfTree, int pLevel) {

// analysing content of conditions of IF node
ExpressionTree expr = pIfTree.condition().expression();
if (expr instanceof BinaryExpressionTree) {
computeConditionVariables((BinaryExpressionTree) expr, pLevel);
if (expr instanceof BinaryExpressionTree bet) {
computeConditionVariables(bet, pLevel);
}

}
Expand All @@ -153,11 +153,11 @@ private void computeConditionVariables(BinaryExpressionTree pBinExprTree, int pL

// if multiple conditions, continue with each part of complex expression
if (pBinExprTree.is(Kind.CONDITIONAL_AND) || pBinExprTree.is(Kind.CONDITIONAL_OR)) {
if (pBinExprTree.leftOperand() instanceof BinaryExpressionTree) {
computeConditionVariables((BinaryExpressionTree) pBinExprTree.leftOperand(), pLevel);
if (pBinExprTree.leftOperand() instanceof BinaryExpressionTree bet) {
computeConditionVariables(bet, pLevel);
}
if (pBinExprTree.rightOperand() instanceof BinaryExpressionTree) {
computeConditionVariables((BinaryExpressionTree) pBinExprTree.rightOperand(), pLevel);
if (pBinExprTree.rightOperand() instanceof BinaryExpressionTree bet) {
computeConditionVariables(bet, pLevel);
}
} else if (pBinExprTree.is(Kind.EQUAL_TO)
|| pBinExprTree.is(Kind.NOT_EQUAL_TO)
Expand Down Expand Up @@ -228,8 +228,8 @@ private void computeElseIfVariables(ElseifClauseTree pElseIfTree, int pLevel) {
if (pElseIfTree.condition() == null) return;

ExpressionTree expr = pElseIfTree.condition().expression();
if (expr instanceof BinaryExpressionTree) {
computeConditionVariables((BinaryExpressionTree) expr, pLevel);
if (expr instanceof BinaryExpressionTree bet) {
computeConditionVariables(bet, pLevel);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package fr.greencodeinitiative.php.checks;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -59,44 +58,18 @@ private void visitStatementsList(List<StatementTree> lstStmts) {
for (StatementTree stmt : lstStmts){
Tree.Kind kind = stmt.getKind();
switch (kind) {
case EXPRESSION_STATEMENT:
visitExpressionStatement(((ExpressionStatementTree) stmt).expression());
break;
case BLOCK:
visitStatementsList(((BlockTree) stmt).statements());
break;
case IF_STATEMENT:
case ALTERNATIVE_IF_STATEMENT:
visitIfStatement((IfStatementTree) stmt);
break;
case FOR_STATEMENT:
case ALTERNATIVE_FOR_STATEMENT:
visitStatementsList(((ForStatementTree) stmt).statements());
break;
case WHILE_STATEMENT:
case ALTERNATIVE_WHILE_STATEMENT:
visitStatementsList(((WhileStatementTree) stmt).statements());
break;
case DO_WHILE_STATEMENT:
visitStatementsList(Arrays.asList(((DoWhileStatementTree) stmt).statement()));
break;
case FOREACH_STATEMENT:
case ALTERNATIVE_FOREACH_STATEMENT:
visitStatementsList(((ForEachStatementTree) stmt).statements());
break;
case CASE_CLAUSE:
visitStatementsList(((CaseClauseTree) stmt).statements());
break;
case SWITCH_STATEMENT:
visitSwitchStatement((SwitchStatementTree) stmt);
break;
case DEFAULT_CLAUSE:
visitStatementsList(((DefaultClauseTree) stmt).statements());
break;
case TRY_STATEMENT:
visitTryStatement((TryStatementTree) stmt);
break;
default:
case EXPRESSION_STATEMENT -> visitExpressionStatement(((ExpressionStatementTree) stmt).expression());
case BLOCK -> visitStatementsList(((BlockTree) stmt).statements());
case IF_STATEMENT, ALTERNATIVE_IF_STATEMENT -> visitIfStatement((IfStatementTree) stmt);
case FOR_STATEMENT, ALTERNATIVE_FOR_STATEMENT -> visitStatementsList(((ForStatementTree) stmt).statements());
case WHILE_STATEMENT, ALTERNATIVE_WHILE_STATEMENT -> visitStatementsList(((WhileStatementTree) stmt).statements());
case DO_WHILE_STATEMENT -> visitStatementsList(Collections.singletonList(((DoWhileStatementTree) stmt).statement()));
case FOREACH_STATEMENT, ALTERNATIVE_FOREACH_STATEMENT -> visitStatementsList(((ForEachStatementTree) stmt).statements());
case CASE_CLAUSE -> visitStatementsList(((CaseClauseTree) stmt).statements());
case SWITCH_STATEMENT -> visitSwitchStatement((SwitchStatementTree) stmt);
case DEFAULT_CLAUSE -> visitStatementsList(((DefaultClauseTree) stmt).statements());
case TRY_STATEMENT -> visitTryStatement((TryStatementTree) stmt);
default -> {}
}
}
}
Expand Down

0 comments on commit 8c4c322

Please sign in to comment.