phpstan banned code
v3.0.0
该库基于 PHPStan,用于检测对项目中不需要的特定函数的调用。例如,您可以将其添加到 CI 进程中,以确保没有调试/非标准代码(如 var_dump、exit 等)。
要使用此扩展,请使用 Composer 要求它:
composer require --dev ekino/phpstan-banned-code
当您使用 https://github.com/phpstan/extension-installer 时,您就完成了。
如果没有,请将extension.neon
包含在项目的 PHPStan 配置中:
includes:
- vendor/ekino/phpstan-banned-code/extension.neon
您可以使用参数配置该库:
parameters:
banned_code:
nodes:
# enable detection of echo
-
type: Stmt_Echo
functions: null
# enable detection of eval
-
type: Expr_Eval
functions: null
# enable detection of die/exit
-
type: Expr_Exit
functions: null
# enable detection of a set of functions
-
type: Expr_FuncCall
functions:
- dd
- debug_backtrace
- dump
- exec
- passthru
- phpinfo
- print_r
- proc_open
- shell_exec
- system
- var_dump
# enable detection of print statements
-
type: Expr_Print
functions: null
# enable detection of shell execution by backticks
-
type: Expr_ShellExec
functions: null
# enable detection of `use TestsFooBar` in a non-test file
use_from_tests: true
# errors emitted by the extension are non-ignorable by default, so they cannot accidentally be put into the baseline.
non_ignorable: false # default is true
type
是节点的返回值,请参阅方法getType()
。