Search by

centaur-vova / ird-meter

dshmanatov

If/Row Density (IRD) calculator for PHP projects — how linear is your code?

Package info

github.com/centaur-vova/ird-meter

pkg:composer/centaur-vova/ird-meter

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.2 2026-09-15 18:51 UTC

This package is auto-updated.

Last update: 2026-09-15 18:54:14 UTC


README

How linear is your code? Number of if statements per 100 lines of code.

CI Packagist Downloads PHP

What is IRD?

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

Install

composer require --dev centaur-vova/ird-meter

Usage

vendor/bin/ird-meter app

Example

📊 PHP 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.

Self-check (Dogfooding)

$ ird-meter src
📊 PHP IRD (If/Row Density)
  If count: 12
  Total lines: 216
  Files: 2
  IRD: 5.56%

  🟠 needs attention — too many ifs

Yes, our own parser has many ifs. It's a parser — it does nothing but check conditions. Irony appreciated.

See TODO.md — we're working on reducing it. PRs welcome.

Flags

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

CI Integration

- name: Check IRD
  run: vendor/bin/ird-meter app --threshold=5

If IRD exceeds threshold — exit code 1, CI fails.

Why IRD?

Because if is the source of all evil:

  • Each if is 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.

Requirements

  • PHP 8.1+
  • nikic/php-parser 5.x

License

MIT. Or KBL v4.0 — horses don't abandon horses, and ponies 🦄