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()
。