ekino/phpstan-banned-code
PHPStan extension to ban unwanted code in your project. Detects calls like var_dump, dd, eval, exit/die, echo/print, shell exec/backticks, and even “use” imports from Tests in non-test files. Configurable rules for CI enforcement.
composer require --dev ekino/phpstan-banned-code
extension-installer (recommended):
composer require --dev phpstan/extension-installer
Or manually include the config in your phpstan.neon:
includes:
- vendor/ekino/phpstan-banned-code/extension.neon
vendor/bin/phpstan analyse
Configure phpstan.neon to ban common debug functions:
parameters:
banned_code:
nodes:
- type: Expr_FuncCall
functions:
- var_dump
- dd
- dump
- exit
- die
- name: PHPStan Banned Code Check
run: vendor/bin/phpstan analyse --level=max --error-format=github
non_ignorable: true).phpstan.neon config (e.g., config/phpstan.neon).parameters:
banned_code:
nodes:
- type: Expr_FuncCall
functions:
- customDebugHelper
- internalDebugTool
use Tests\* in non-test files:
parameters:
banned_code:
use_from_tests: true
non_ignorable: true) to catch critical issues.parameters:
banned_code:
nodes:
- type: Expr_FuncCall
functions:
- var_dump # Temporarily allowed
non_ignorable: false temporarily to baseline existing issues.mysql_* functions may trigger false alarms.Variable node conflicts).vendor/bin/phpstan analyse --generate-baseline before enforcing.phpstan debug:container to verify node types (e.g., Stmt_Echo).functions: are case-sensitive (e.g., VarDump ≠ var_dump).BannedNodesRule to support new node types (e.g., Stmt_Throw for banned exceptions).parameters to load banned functions from a config file or environment variable.booted event to auto-configure PHPStan for banned code checks.// app/Providers/AppServiceProvider.php
public function boot()
{
if (app()->environment('production')) {
$this->configureBannedCodeRules();
}
}
use_from_tests if test files are excluded from analysis.--parallel flag to speed up scans in monorepos.APP_DEBUG=false in production to enforce zero-debug rules.dd() in AppServiceProvider constructors to prevent accidental debug leaks:
parameters:
banned_code:
nodes:
- type: Expr_FuncCall
functions:
- dd
file_patterns:
- "app/Providers/AppServiceProvider.php"
How can I help you explore Laravel packages today?