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)。請參閱許可證文件以獲取更多資訊。