Method calculate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private long calculate(File file) {
if (file.isDirectory()) {
long result = 0;
File[] files = file.listFiles();
if (files == null) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
'}' at column 50 should be alone on a line. Open
public FileSize(File file) {this.file = file;}
- Read upRead up
- Exclude checks
Checks the placement of right curly braces ('}'
) for code blocks.This check supports if-else, try-catch-finally blocks, while-loops, for-loops,method definitions, class definitions, constructor definitions,instance, static initialization blocks, annotation definitions and enum definitions.For right curly brace of expression blocks of arrays, lambdas and class instancesplease follow issue#5945.For right curly brace of enum constant please follow issue#7519.
This documentation is written and maintained by the Checkstyle community and is covered under the same license as the Checkstyle project.