private List<TestComplexityComponent> components(String functionBody) throws Exception { FunctionTree tree = parse("function f() { " + functionBody + " }", PHPLexicalGrammar.FUNCTION_DECLARATION); CognitiveComplexity complexity = CognitiveComplexityVisitor.complexity(tree); return complexity.getComplexityComponents().stream().map(TestComplexityComponent::create).collect(Collectors.toList()); }
private void checkFunctionComplexity(FunctionTree functionTree) { CognitiveComplexity complexity = CognitiveComplexityVisitor.complexity(functionTree); if (complexity.getValue() > threshold) { String message = String.format(MESSAGE, complexity.getValue(), threshold); int cost = complexity.getValue() - threshold; PreciseIssue issue = context().newIssue(this, (functionTree).functionToken(), message).cost(cost); complexity.getComplexityComponents().forEach(complexityComponent -> issue.secondary( complexityComponent.tree(), secondaryMessage(complexityComponent.addedComplexity()))); } }
private void addComplexityWithNesting(SyntaxToken secondaryLocationToken) { addComplexityWithoutNesting(secondaryLocationToken, level + 1); }
private void addComplexityWithoutNesting(SyntaxToken secondaryLocationToken) { addComplexityWithoutNesting(secondaryLocationToken, 1); }
private void addComplexityWithNesting(SyntaxToken secondaryLocationToken) { addComplexityWithoutNesting(secondaryLocationToken, level + 1); }
private void addComplexityWithoutNesting(SyntaxToken secondaryLocationToken) { addComplexityWithoutNesting(secondaryLocationToken, 1); }
private int complexity(String functionBody) throws Exception { FunctionTree tree = parse("function f() { " + functionBody + " }", PHPLexicalGrammar.FUNCTION_DECLARATION); CognitiveComplexity complexity = CognitiveComplexityVisitor.complexity(tree); return complexity.getValue(); }
private void checkFunctionComplexity(FunctionTree functionTree) { CognitiveComplexity complexity = CognitiveComplexityVisitor.complexity(functionTree); if (complexity.getValue() > threshold) { String message = String.format(MESSAGE, complexity.getValue(), threshold); int cost = complexity.getValue() - threshold; PreciseIssue issue = context().newIssue(this, (functionTree).functionToken(), message).cost(cost); complexity.getComplexityComponents().forEach(complexityComponent -> issue.secondary( complexityComponent.tree(), secondaryMessage(complexityComponent.addedComplexity()))); } }