churn php
Release 1.7.2
帮助发现重构的良好候选者。
churn-php
是一个包,可帮助您识别项目中可能适合重构的 php 文件。它检查提供的路径中的每个 PHP 文件,并且:
结果显示在表格中:
更改较多且复杂性较高的文件可能比更改较少且复杂性较低的文件更适合重构。
churn-php
仅帮助开发人员识别要重构的文件。除了您自己的判断之外,最好还使用结果来决定您可能想要重构哪些文件。
下载最新版本的churn.phar
或使用 Phive 安装它:
phive install churn
您还可以通过 Composer 安装churn-php
:
composer require bmitch/churn-php --dev
churn run < one or more paths to source code > ...
churn run src
churn run src tests
# the command name can be skipped if directoriesToScan is set in churn.yml
churn
您可以添加一个可选的churn.yml
文件,该文件可用于配置 churn-php。可以使用--configuration
选项自定义该文件的位置:
# Default: "churn.yml" or "churn.yml.dist"
churn run --configuration=config-dir/ < path >
churn run --configuration=my-config.yml < path >
示例churn.yml
文件如下所示:
# The maximum number of files to display in the results table.
# Default: 10
filesToShow : 10
# The minimum score a file need to display in the results table.
# Disabled if null.
# Default: 0.1
minScoreToShow : 0
# The command returns an 1 exit code if the highest score is greater than the threshold.
# Disabled if null.
# Default: null
maxScoreThreshold : 0.9
# The number of parallel jobs to use when processing files.
# Default: 10
parallelJobs : 10
# How far back in the VCS history to count the number of commits to a file
# Can be a human readable date like 'One week ago' or a date like '2017-07-12'
# Default: '10 Years ago'
commitsSince : One year ago
# Files to ignore when processing. The full path to the file relative to the root of your project is required.
# Also supports regular expressions.
# Default: All PHP files in the path provided to churn-php are processed.
filesToIgnore :
- src/Commands/ChurnCommand.php
- src/Results/ResultsParser.php
- src/Foo/Ba*
# File extensions to use when processing.
# Default: php
fileExtensions :
- php
- inc
# This list is used only if there is no argument when running churn.
# Default: <empty>
directoriesToScan :
- src
- tests/
# List of user-defined hooks.
# They can be referenced by their full qualified class name if churn has access to the autoloader.
# Otherwise the file path can be used as well.
# See below the section about hooks for more details.
# Default: <empty>
hooks :
- NamespaceMyHook
- path/to/my-hook.php
# The version control system used for your project.
# Accepted values: fossil, git, mercurial, subversion, none
# Default: git
vcs : git
# The path of the cache file. It doesn't need to exist before running churn.
# Disabled if null.
# Default: null
cachePath : .churn.cache
如果省略churn.yml
文件或省略单个设置,则将使用上面的默认值。
您可以配置churn
以不同的格式输出结果。可用的格式有:
csv
json
markdown
text
(默认)要使用不同的格式,请使用--format
选项。 json
命令示例:
churn run --format json
hooks配置允许您自定义churn
。
用户定义的钩子必须至少实现一个 Hook 接口:
挂钩接口 | 对应事件接口 |
---|---|
分析后钩子 | 事后分析 |
文件分析后钩子 | 文件分析后 |
分析前钩子 | 分析前 |
有问题、评论、反馈吗? @bmitch2112
composer test
并确保它通过。麻省理工学院许可证 (MIT)。请参阅许可证文件以获取更多信息。