# eric7.Plugins.CheckerPlugins.CodeStyleChecker.Complexity.ComplexityChecker

Module implementing a checker for code complexity.

### Global Attributes

None

### Classes

ComplexityChecker | Class implementing a checker for code complexity.
LineComplexityVisitor | Class calculating the number of AST nodes per line of code and the median nodes/line score.

### Functions

None

## ComplexityChecker

Class implementing a checker for code complexity.

### Derived from

None

### Class Attributes

Codes

### Class Methods

None

### Methods

ComplexityChecker | Constructor
__checkLineComplexity | Private method to check the complexity of a single line of code and the median line complexity of the source code.
__checkMcCabeComplexity | Private method to check the McCabe code complexity.
__error | Private method to record an issue.
__ignoreCode | Private method to check if the message code should be ignored.
run | Public method to check the given source for code complexity.

### Static Methods

None

#### ComplexityChecker (Constructor)

ComplexityChecker(source, filename, tree, select, ignore, args)

Constructor

source (list of str)
  source code to be checked
filename (str)
  name of the source file
tree (ast.Module)
  AST tree of the source code
select (list of str)
  list of selected codes
ignore (list of str)
  list of codes to be ignored
args (dict)
  dictionary of arguments for the miscellaneous checks

#### ComplexityChecker.__checkLineComplexity

__checkLineComplexity()

Private method to check the complexity of a single line of code and the median line complexity of the source code.

Complexity is defined as the number of AST nodes produced by a line of code.

#### ComplexityChecker.__checkMcCabeComplexity

__checkMcCabeComplexity()

Private method to check the McCabe code complexity.

#### ComplexityChecker.__error

__error(lineNumber, offset, code, *args)

Private method to record an issue.

lineNumber (int)
  line number of the issue
offset (int)
  position within line of the issue
code (str)
  message code
args (list)
  arguments for the message

#### ComplexityChecker.__ignoreCode

__ignoreCode(code)

Private method to check if the message code should be ignored.

code (str)
  message code to check for

Return:
  flag indicating to ignore the given code

Return Type:
  bool

#### ComplexityChecker.run

run()

Public method to check the given source for code complexity.

Up

## LineComplexityVisitor

Class calculating the number of AST nodes per line of code and the median nodes/line score.

### Derived from

ast.NodeVisitor

### Class Attributes

None

### Class Methods

None

### Methods

LineComplexityVisitor | Constructor
score | Public method to calculate the median.
sortedList | Public method to get a sorted list of (line, nodes) tuples.
visit | Public method to recursively visit all the nodes and add up the instructions.

### Static Methods

None

#### LineComplexityVisitor (Constructor)

LineComplexityVisitor()

Constructor

#### LineComplexityVisitor.score

score()

Public method to calculate the median.

Return:
  median line complexity value

Return Type:
  float

#### LineComplexityVisitor.sortedList

sortedList()

Public method to get a sorted list of (line, nodes) tuples.

Return:
  sorted list of (line, nodes) tuples

Return Type:
  list of tuple of (int,int)

#### LineComplexityVisitor.visit

visit(node)

Public method to recursively visit all the nodes and add up the instructions.

node (ast.AST)
  reference to the node

Up