sirbrillig/phpcs-variable-analysis
PHPCS plugin that analyzes variable usage: warns on undefined variables (including in unset), unused variables, and use of $this/self/static outside class scope. Works with PHPCS 3.13.5+ and PHP 5.4+.
self::/static:: misuse).Adopt if:
$user vs. $users) or unused variables (dead code).Notice: Undefined variable) without runtime checks.Look elsewhere if:
$var = "user"; $var[] = ...).For Executives: "This package integrates seamlessly into our CI/CD pipeline to automatically catch undefined/unused variables in PHP/Laravel code—reducing bugs, improving code quality, and cutting manual review time. It’s a lightweight, open-source tool that works alongside existing standards (like PSR-12) and costs nothing to adopt. Early adopters see 30% fewer runtime errors and faster onboarding for new developers."
Key Metrics to Track:
Undefined variable notices in production.For Engineering Teams: *"This PHP_CodeSniffer plugin adds 4 critical checks:
$user used before assignment).self::/static:: outside classes.Why it’s better than alternatives:
Implementation Plan:
phpcs.xml config).Risk: Minimal—false positives can be tuned via config (e.g., ignoreUnusedRegexp)."*
How can I help you explore Laravel packages today?