@Test public void declarations() throws Exception { assertOneComplexityToken("function f() {}", "function"); assertOneComplexityToken("$f = function() {};", "function"); assertOneComplexityToken("$f = fn() => 0;", "fn"); assertThat(complexity("class A {}")).isEqualTo(0); assertOneComplexityToken("class A { public function f() {} }", "function"); assertThat(complexity("function f() { f(); return; }")).isEqualTo(1); assertThat(complexity("function f() { return; f(); }")).isEqualTo(1); assertThat(complexity("class A { abstract function f(); }")).isEqualTo(1); assertThat(expressionComplexity("function() { return $a && $b; };")).isEqualTo(2); assertThat(expressionComplexity("fn() => $a && $b;")).isEqualTo(2); }
public static int complexity(Tree tree) { return complexityTrees(tree).size(); }
ComplexityVisitor extends PHPVisitorCheck { public static int complexity(Tree tree) { return complexityTrees(tree).size(); } }
ComplexityVisitor extends PHPVisitorCheck { public static int complexity(Tree tree) { return complexityTrees(tree).size(); }  }
ComplexityVisitor extends PHPVisitorCheck { public static int complexity(Tree tree) { return complexityTrees(tree).size(); }  @Override void visitCaseClause(CaseClauseTree tree); @Override void visitWhileStatement(WhileStatementTree tree); @Override void visitDoWhileStatement(DoWhileStatementTree tree); @Override void visitIfStatement(IfStatementTree tree); @Override void visitForStatement(ForStatementTree tree); @Override void visitForEachStatement(ForEachStatementTree tree); @Override void visitConditionalExpression(ConditionalExpressionTree tree); @Override void visitBinaryExpression(BinaryExpressionTree tree); @Override void visitMethodDeclaration(MethodDeclarationTree tree); @Override void visitFunctionDeclaration(FunctionDeclarationTree tree); @Override void visitFunctionExpression(FunctionExpressionTree tree); @Override void visitArrowFunctionExpression(ArrowFunctionExpressionTree tree); static int complexity(Tree tree); static List<Tree> complexityTrees(Tree tree); static List<Tree> complexityNodesWithoutNestedFunctions(Tree tree); }
ComplexityVisitor extends PHPVisitorCheck { public static int complexity(Tree tree) { return complexityTrees(tree).size(); }  @Override void visitCaseClause(CaseClauseTree tree); @Override void visitWhileStatement(WhileStatementTree tree); @Override void visitDoWhileStatement(DoWhileStatementTree tree); @Override void visitIfStatement(IfStatementTree tree); @Override void visitForStatement(ForStatementTree tree); @Override void visitForEachStatement(ForEachStatementTree tree); @Override void visitConditionalExpression(ConditionalExpressionTree tree); @Override void visitBinaryExpression(BinaryExpressionTree tree); @Override void visitMethodDeclaration(MethodDeclarationTree tree); @Override void visitFunctionDeclaration(FunctionDeclarationTree tree); @Override void visitFunctionExpression(FunctionExpressionTree tree); @Override void visitArrowFunctionExpression(ArrowFunctionExpressionTree tree); static int complexity(Tree tree); static List<Tree> complexityTrees(Tree tree); static List<Tree> complexityNodesWithoutNestedFunctions(Tree tree);  }