tomokinakamaru / phinder
v0.9.4
2021-12-30 04:45 UTC
Requires
- php: >=7.3
- nikic/php-parser: 4.*
- symfony/console: ^5.3.7
- symfony/yaml: ^5.3.6
Requires (Dev)
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: 3.*
- swaggest/json-diff: ^3.5
- dev-master
- v0.9.4.x-dev
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- 0.5.0.x-dev
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.0
- dev-dependabot/composer/symfony/yaml-tw-5.4.3
- dev-dependabot/composer/symfony/console-tw-5.4.3
- dev-dependabot/composer/phpunit/phpunit-tw-9.5
- dev-dependabot/composer/swaggest/json-diff-tw-3.8
- dev-php8
- dev-bump-0.9.3
- dev-remove-docker
- dev-bump-dependencies
- dev-new-branch
- dev-add_logo
- dev-fix/issue42
- dev-doc
- dev-fix/issue33
- dev-fix/issue34
This package is not auto-updated.
Last update: 2022-02-01 13:14:24 UTC
README
Phinder:PHP代码片段查找器
Phinder是一个用于查找代码片段的工具。这个工具主要目的是加快你的代码审查过程,而不是静态错误检测。
假设你的项目有以下本地规则
- 在调用
in_array时显式指定第三个参数,以避免意外的比较结果。
如果你的项目代码遵循此规则,你可以在代码审查中检查它。但是,如果你忘记了检查呢?如果你的项目有几十条规则呢?你可能希望机器做这样的低级别检查。
Phinder是一个用于自动检查此类低级别问题的命令行工具。通过将以下yml保存为phinder.yml并在你的终端中运行phinder,Phinder会为你找到违规行为。
- id: in_array_without_3rd_param pattern: in_array(_, _) message: Specify the 3rd parameter explicitly when calling `in_array` to avoid unexpected comparison results.
安装
Phinder需要PHP >= 7.3。你可以使用Composer进行安装。
composer require --dev sider/phinder vendor/bin/phinder -v
快速入门
第一步,你可以运行phinder init命令来创建一个示例phinder.yml。
$ phinder init `phinder.yml` has been created successfully $ cat phinder.yaml # Feel free to add your own project rules to this YAML file. # The following example describes the rule syntax. # See the documentation for more details: https://github.com/sider/phinder/tree/master/doc - # The rule identifier. It must be unique in the YAML file. id: sample.var_dump # Pattern syntax. The `...` pattern matches variable length arguments or array pairs. # As a result, this pattern matches `var_dump` function call with any arguments. pattern: var_dump(...) # The message to display when code pieces are matched with the pattern. message: Do not use var_dump. # Exceptions that can ignore this violation. justification: Allowed when debugging - id: sample.in_array_without_3rd_param # `_` pattern mattches any single expression. # This means the pattern always matches `in_array` function call with any two arguments. pattern: in_array(_, _) message: Specify 3rd parameter explicitly when calling in_array to avoid unexpected comparison results. # You can test whether your pattern works as expected with `phinder test`. test: # Code pieces that will match your pattern. # This means the following codes are bad as you expected. fail: - in_array(1, $arr) - in_array(2, $arr) # Code pieces that will NOT match your pattern. # This means the following codes are good as you expected. pass: - in_array(3, $arr, true) - in_array(4, $arr, false)
然后你可以运行phinder命令来对你的代码进行phind模式匹配。
$ phinder find
在了解了一个模式是如何匹配你的代码之后,让我们为你的项目添加更多有用的规则吧!
文档
贡献
欢迎在GitHub上提交错误报告、功能请求和拉取请求,网址为https://github.com/sider/phinder。
