How linear is your code? Number of
ifstatements per 100 lines of code.
IRD = number of if statements per 100 lines of code.
It shows how linear your code is. Fewer ifs — more predictable flow.
| IRD | Meaning |
|---|---|
| < 2% | 🟢 clean |
| 2–5% | 🟡 good |
| 5–10% | 🟠 needs attention |
| > 10% | 🔴 for ponies |
composer require --dev centaur-vova/ird-metervendor/bin/ird-meter appPHP IRD (If/Row Density)
If count: 111
Total lines: 5807
Files: 96
IRD: 1.91%
clean — this code is linear like a horse's path
With --ignore-comments:
PHP IRD (If/Row Density)
If count: 111
Total lines: 3826
Files: 96
IRD: 2.90%
good — some branches, but manageable
The difference: 1981 lines (34%) are comments and PHPDoc.
PHP IRD (If/Row Density)
If count: 9
Total lines: 257
Files: 3
IRD: 3.50%
good — some branches, but manageable
Yes, our own parser has a few ifs. It's a parser — it does nothing but check conditions. Irony appreciated.
See TODO.md — we're working on reducing it. PRs welcome.
| Flag | Description |
|---|---|
--raw |
Output only the IRD number |
--json |
Output JSON |
--threshold=N |
Exit 1 if IRD > N (for CI) |
--exclude=A,B |
Comma-separated directories to exclude (default: vendor,.git,node_modules,var/cache) |
--ignore-comments |
Count only non-comment, non-empty lines |
--include-elseif |
Count elseif branches too |
--include-ternary |
Count ternary operators |
--include-match |
Count match expressions |
--all |
Enable all optional counters |
--help, -h |
Show this help |
- name: Check IRD
run: vendor/bin/ird-meter app --threshold=5If IRD exceeds threshold — exit code 1, CI fails.
Because if is the source of all evil:
- Each
ifis a branch - Each branch is a potential bug
- Fewer branches — fewer bugs
Based on nikic/php-parser — accurate AST analysis, no regex, no false positives from comments or strings.
- PHP 8.1+
nikic/php-parser5.x
MIT. Or KBL v4.0 — horses don't abandon horses, and ponies 🦄