diff --git a/src/main/java/fr/greencodeinitiative/php/checks/AvoidMultipleIfElseStatementCheck.java b/src/main/java/fr/greencodeinitiative/php/checks/AvoidMultipleIfElseStatementCheck.java index 2322d5f..56d6a3e 100644 --- a/src/main/java/fr/greencodeinitiative/php/checks/AvoidMultipleIfElseStatementCheck.java +++ b/src/main/java/fr/greencodeinitiative/php/checks/AvoidMultipleIfElseStatementCheck.java @@ -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); } } @@ -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) @@ -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); } } diff --git a/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchWithFileOpenedCheck.java b/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchWithFileOpenedCheck.java index 6c83da4..0c22c57 100644 --- a/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchWithFileOpenedCheck.java +++ b/src/main/java/fr/greencodeinitiative/php/checks/AvoidTryCatchWithFileOpenedCheck.java @@ -17,7 +17,6 @@ */ package fr.greencodeinitiative.php.checks; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -59,44 +58,18 @@ private void visitStatementsList(List 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 -> {} } } }