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.0You can show the Halstead Complexity and the Cyclomatic Complexity in the output by setting the following configuration options to true, the default is false.
This can be useful to get a better understanding of the complexity of your code. Keep in mind that each of them measures a different aspect of complexity, so it is recommended to use them in conjunction with cognitive complexity.
cognitive:
showHalsteadComplexity: false
showCyclomaticComplexity: falseYou can control how the analysis results are displayed by setting the groupByClass option.
cognitive:
groupByClass: truetrue(default): Results are grouped by class, showing all methods within each class togetherfalse: Results are displayed as a flat list without grouping
When groupByClass is enabled, the output will show separate tables for each class, making it easier to understand the complexity within specific classes. When disabled, all methods are shown in a single table sorted by their complexity score.