ekino / phpstan-banned-code
使用 PHPStan 检测到的禁止代码
v2.1.0
2024-08-14 07:20 UTC
Requires
- php: ^8.1
- phpstan/phpstan: ^1.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.6
- friendsofphp/php-cs-fixer: ^3.0
- nikic/php-parser: ^4.3
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
- symfony/var-dumper: ^5.0
- v2.1.0
- v2.0.0
- dev-master / 1.0.x-dev
- v1.0.0
- v0.5.0
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.0
- v0.1.1
- v0.1.0
- v0.0.2
- v0.0.1
- dev-dependabot/composer/nikic/php-parser-tw-5.2
- dev-dependabot/composer/phpunit/phpunit-tw-11.2
- dev-dependabot/composer/symfony/var-dumper-tw-7.1
- dev-dependabot/composer/nikic/php-parser-tw-5.1
- dev-dependabot/composer/phpunit/phpunit-tw-9.5
This package is auto-updated.
Last update: 2024-09-16 04:20:43 UTC
README
这个库基于 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 Tests\Foo\Bar` 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()
方法。