spaze/phpstan-disallowed-calls
PHPStan extension to define and enforce a denylist of disallowed function and method calls in your codebase. Catch legacy, unsafe, or unwanted APIs during static analysis with configurable rules and helpful error messages.
file_get_contents in production, legacy mysql_* functions). Aligns with shift-left security and compliance (e.g., PCI, GDPR).eval(), dynamic function calls) to identify tech debt.str_replace in security-sensitive modules).create_function, call_user_func_array with dynamic args) due to security or architectural constraints.json_encode in API handlers but block it elsewhere).disallowedTypes for arguments)."This tool is like a ‘static code firewall’ for PHP. It automatically catches risky or deprecated function calls (e.g., security holes, performance anti-patterns) before they reach production—saving us from vulnerabilities and tech debt. For example, it can block eval() or dynamic SQL queries in new code, while letting our legacy payment system (which uses mysql_connect) keep running during migration. It’s low-cost (MIT license), integrates with our existing CI, and reduces the burden on QA by catching issues early. Think of it as insurance for our codebase."
Ask: "Would you prioritize reducing security incidents and maintenance costs over a small upfront setup effort?"
*"This extends PHPStan to enforce a whitelist of allowed calls, which is critical for:
eval(), shell_exec(), or unsafe preg_replace callbacks.str_replace in string-heavy codebases where Str::of() is preferred.mysql_* calls in new PRs while grandfathering existing systems.How it works:
phpstan.neon (e.g., disallowedFunctions: ['eval', 'create_function']).@phpstan-disallowed annotations to temporarily allow calls in specific places (e.g., legacy payment code).Trade-offs:
Next steps:
str_replace’)."*Ask: "Can we allocate 2 hours to configure this and test it on a sample module?"
How can I help you explore Laravel packages today?