sirbrillig/phpcs-variable-analysis
Static analysis rules for PHP_CodeSniffer that detect undefined, unused, and improperly scoped variables in PHP code. Helps enforce cleaner code, catches subtle variable bugs early, and improves overall code quality in CI and local linting workflows.
Start by installing the package via Composer: composer require --dev sirbrillig/phpcs-variable-analysis. Then configure PHP_CodeSniffer to use its custom sniff: add <rule ref="VariableAnalysis"> to your phpcs.xml (or phpmd.xml if using PHPCS with custom rulesets). The default configuration catches undefined variables and unused variables across functions, methods, closures, and conditionals — run phpcs on your codebase to see immediate feedback.
phpcs to block PRs with variable issues.ignoreByReference, allowUnusedByReferenceParameters) in phpcs.xml to match team conventions.--sniffs=VariableAnalysis.Variables.UnusedVariable or similar flags to focus on specific problems during audits.__get, __set, etc.) by overriding allowMagicGetSet in the sniff config.use (&$var) to silence unused warnings for known captures.compact() are often misflagged as unused — whitelist them with <property name="allowExtractVariables" value="true"/>.<rule ref="VariableAnalysis"> after PSR rules in your phpcs.xml to prevent syntax errors from masking analysis issues.-s flag to phpcs to see sniff names in output, helping trace which rule triggered a warning.How can I help you explore Laravel packages today?