You can specify another configuration file by passing it to the config options:
bin/phpcca analyse <path-to-folder> --config=<path-to-config-file>
You can exclude classes and methods via a regex in the configuration.
The following configuration will exclude all constructors, toArray
methods and all methods of classes that end with Transformer
.
cognitive:
excludePatterns:
- '(.*)::__construct'
- '(.*)::toArray'
- '(.*)Transformer::(.*)'
You can exclude files via a regex in the configuration.
cognitive:
excludeFilePatterns:
- '.*Cognitive.*'
- '(.*)Test.php'
The configuration file can contain the following settings for the calculation of cognitive complexity.
Feel free to adjust the values to your match your opinion on what makes code complex. It is recommended to play with the values until you get weights that you are comfortable with. The default values are a good starting point.
cognitive:
metrics:
lineCount:
threshold: 60
scale: 2.0
argCount:
threshold: 4
scale: 1.0
returnCount:
threshold: 2
scale: 5.0
variableCount:
threshold: 2
scale: 5.0
propertyCallCount:
threshold: 2
scale: 15.0
ifCount:
threshold: 3
scale: 1.0
ifNestingLevel:
threshold: 1
scale: 1.0
elseCount:
threshold: 1
scale: 1.0