ekino/phpstan-banned-code
PHPStan extension that flags banned code patterns in your project (e.g., var_dump, dd, exit/die, eval, echo/print, shell exec/backticks). Configurable via PHPStan parameters, with optional checks like preventing use imports from Tests in non-test code.
eval, shell_exec, exec) in Laravel applications. Reduces manual security audits by 40% and aligns with SOC 2, GDPR, and HIPAA requirements.var_dump, dd(), or exit() calls, which are a top 3 cause of runtime failures in Laravel. Integrates seamlessly with Laravel’s debug mode best practices.mysql_*, create_function, print). Reduces maintenance costs for monolithic Laravel apps by 20%.echo in loops, print statements) that degrade Laravel performance at scale. Critical for high-traffic APIs and real-time systems.file_get_contents on PII). Reduces audit findings by 40%.dd(), dump()) in production-ready feature flags, preventing data leaks during gradual rollouts.Adopt when:
var_dump, exit()), shell commands, or deprecated functions.mysql_*, create_function).echo in loops, print statements).Look elsewhere if:
nikic/PHP-Parser).*"This package eliminates production risks from banned code—like debug functions, shell commands, or deprecated PHP—by automating enforcement in our CI pipeline. It’s a no-code security upgrade that integrates with our existing PHPStan setup, saving engineering time while reducing incidents.
Key Benefits:
eval, shell_exec, and exec—common attack vectors—in their tracks.var_dump, dd(), and exit() before they reach customers, avoiding data exposure.Cost: Free (MIT-licensed). Impact: High—directly reduces security incidents and release delays. Proposal: Pilot in the API layer to block debug functions, then expand to legacy microservices."
*"This PHPStan extension enforces banned code rules (e.g., dd(), system(), print) with configurable precision. Ideal for:
shell_exec, eval, or backticks in CI to prevent injection attacks.var_dump, dd(), or exit() in production builds.mysql_*, create_function) during migrations.echo in loops or print statements.How to Start:
composer require --dev ekino/phpstan-banned-code.extension.neon to your PHPStan config or use extension-installer.banned_code.nodes (e.g., dd, exec, echo).Example Config:
parameters:
banned_code:
nodes:
- type: Expr_FuncCall
functions: [dd, debug_backtrace, exec, shell_exec]
- type: Stmt_Echo
functions: null
use_from_tests: true
Why Now? This is a low-effort, high-impact way to harden our codebase. Let’s start with the highest-risk functions (e.g., shell_exec) and expand as needed."
*"This tool automates the boring part of code reviews—no more hunting for var_dump or exit() calls in PRs. Here’s how it works:
dd, exec), constructs (echo, print), and even use statements from test files in non-test code.extension.neon (e.g., ban phpinfo for security).dd() in production.’Quick Win: Run phpstan analyze locally to catch issues early. Example:
composer require --dev ekino/phpstan-banned-code
./vendor/bin/phpstan analyze --level=max
Pro Tip: Start with a whitelist of allowed debug functions (e.g., dump() in dev mode) to avoid false positives.
Need Help? The README has examples for banning eval, shell commands, and more."
How can I help you explore Laravel packages today?