Complexity¶
Complexity refers to how difficult the code is to understand, maintain, test, and modify. It may be objectively measured, but also subjectively estimated.
Complexity is measured with cyclomatic complexity, cognitive complexity, algorithmic complexity.
Complexity increases when:
code takes many decisions in one context
logic is deeply nested
responsibilities are mixed and matched
behavior is not obvious, and includes magic
code is not readable
naming is confusing
Non-complex code tends to:
have small functions
clear naming
limited branching
avoid exploding combinaisons as much as possible
Code complexity applies to all programming languages, and is not specific to PHP.
See also Code Complexity: An In-Depth Explanation and Metrics and What is Code Complexity?.
Related : Cognitive Complexity, Cyclomatic Complexity, Algorithmic Complexity
Related packages : sebastian/complexity, phpmetrics/phpmetrics