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 combinations as much as possible
Code complexity applies to all programming languages, and is not specific to PHP.