@Test public void try_catch() throws Exception { assertThat(complexity("try {} finally {}")).isEqualTo(0); assertThat(complexity("try {} catch (Exc $e) {} ")).isEqualTo(1); assertThat(complexity("try {} catch (Exc $e) {} catch (Exc $e) {}")).isEqualTo(2); assertThat(complexity("try { if($a) {} }")).isEqualTo(1); assertThat(complexity("try {} finally { if($a) {} }")).isEqualTo(1); assertThat(complexity("try {} catch (Exc $e) { if($a) {} }")).isEqualTo(3); assertThat(complexity("if ($a) { try {} catch (Exc $e) {} }")).isEqualTo(3); assertThat(components("try {} catch (Exc $e) {} ")).containsExactly(cc("catch", 1)); }
public static CognitiveComplexity complexity(FunctionTree functionTree) { CognitiveComplexityVisitor cognitiveComplexityVisitor = new CognitiveComplexityVisitor(); cognitiveComplexityVisitor.scan(functionTree); return cognitiveComplexityVisitor.complexity; }
CognitiveComplexityVisitor extends PHPVisitorCheck { public static CognitiveComplexity complexity(FunctionTree functionTree) { CognitiveComplexityVisitor cognitiveComplexityVisitor = new CognitiveComplexityVisitor(); cognitiveComplexityVisitor.scan(functionTree); return cognitiveComplexityVisitor.complexity; } }
CognitiveComplexityVisitor extends PHPVisitorCheck { public static CognitiveComplexity complexity(FunctionTree functionTree) { CognitiveComplexityVisitor cognitiveComplexityVisitor = new CognitiveComplexityVisitor(); cognitiveComplexityVisitor.scan(functionTree); return cognitiveComplexityVisitor.complexity; }  }
CognitiveComplexityVisitor extends PHPVisitorCheck { public static CognitiveComplexity complexity(FunctionTree functionTree) { CognitiveComplexityVisitor cognitiveComplexityVisitor = new CognitiveComplexityVisitor(); cognitiveComplexityVisitor.scan(functionTree); return cognitiveComplexityVisitor.complexity; }  static CognitiveComplexity complexity(FunctionTree functionTree); static int complexity(CompilationUnitTree cut); @Override void visitIfStatement(IfStatementTree tree); @Override void visitElseifClause(ElseifClauseTree tree); @Override void visitElseClause(ElseClauseTree tree); @Override void visitSwitchStatement(SwitchStatementTree tree); @Override void visitWhileStatement(WhileStatementTree tree); @Override void visitDoWhileStatement(DoWhileStatementTree tree); @Override void visitForStatement(ForStatementTree tree); @Override void visitForEachStatement(ForEachStatementTree tree); @Override void visitCatchBlock(CatchBlockTree tree); @Override void visitFunctionDeclaration(FunctionDeclarationTree tree); @Override void visitFunctionExpression(FunctionExpressionTree tree); @Override void visitArrowFunctionExpression(ArrowFunctionExpressionTree tree); @Override void visitMethodDeclaration(MethodDeclarationTree tree); @Override void visitConditionalExpression(ConditionalExpressionTree tree); @Override void visitBreakStatement(BreakStatementTree tree); @Override void visitContinueStatement(ContinueStatementTree tree); @Override void visitGotoStatement(GotoStatementTree tree); @Override void visitBinaryExpression(BinaryExpressionTree tree); }
CognitiveComplexityVisitor extends PHPVisitorCheck { public static CognitiveComplexity complexity(FunctionTree functionTree) { CognitiveComplexityVisitor cognitiveComplexityVisitor = new CognitiveComplexityVisitor(); cognitiveComplexityVisitor.scan(functionTree); return cognitiveComplexityVisitor.complexity; }  static CognitiveComplexity complexity(FunctionTree functionTree); static int complexity(CompilationUnitTree cut); @Override void visitIfStatement(IfStatementTree tree); @Override void visitElseifClause(ElseifClauseTree tree); @Override void visitElseClause(ElseClauseTree tree); @Override void visitSwitchStatement(SwitchStatementTree tree); @Override void visitWhileStatement(WhileStatementTree tree); @Override void visitDoWhileStatement(DoWhileStatementTree tree); @Override void visitForStatement(ForStatementTree tree); @Override void visitForEachStatement(ForEachStatementTree tree); @Override void visitCatchBlock(CatchBlockTree tree); @Override void visitFunctionDeclaration(FunctionDeclarationTree tree); @Override void visitFunctionExpression(FunctionExpressionTree tree); @Override void visitArrowFunctionExpression(ArrowFunctionExpressionTree tree); @Override void visitMethodDeclaration(MethodDeclarationTree tree); @Override void visitConditionalExpression(ConditionalExpressionTree tree); @Override void visitBreakStatement(BreakStatementTree tree); @Override void visitContinueStatement(ContinueStatementTree tree); @Override void visitGotoStatement(GotoStatementTree tree); @Override void visitBinaryExpression(BinaryExpressionTree tree);  }