pem-fr/phpwtf

此工具允许对任何语言的源文件进行静默的人代码审查,并生成可用于Jenkins等工具的报告。

dev-master 2015-08-25 13:32 UTC

This package is auto-updated.

Last update: 2024-09-29 04:14:07 UTC


README

这是什么?

你知道Pdepend,PHPMD吗?这是一个PHP的WTF计数器,用于代码审查。其概念很简单,当你审查一些代码时,如果你认为

  • WTF!?
  • 为什么?为什么?为什么!!!

你只需在需要解释或修复的代码前后添加注释@wtf_start和@wtf_stop。PHPWTF将解析代码并报告找到的WTF。理想情况下,我们甚至可以使其与Jenkins兼容,并通过图形和代码探索使用它:)

安装

/!\ 必须使用COMPOSER安装此工具:https://github.com/composer/composer

如果你已经知道如何使用composer,可以跳过这部分内容,直接转到使用部分。

基本上你需要做的是

  1. 创建一个目录,用于运行你的composer安装,例如:phpwtf_test
  2. 将composer.phar下载到你的phpwtf_test文件夹
  3. 在phpwtf_test文件夹中创建一个composer.json文件,如下所示
    {
    	"name": "nameOfYourProject",
    	"minimum-stability": "dev",
    	"require": {
    		"php": ">=5.3.3",
    		"pem-fr/phpwtf": "dev-master"
    	}
    }
  4. 然后,仍然在phpwtf_test文件夹中,运行以下命令行:php composer.phar install
  5. 验证在根目录(在我们的例子中是phpwtf_test)中是否有composer.lock文件和vendor目录。
  6. 恭喜你,你已经通过composer安装了phpwtf:)

使用方法

要运行示例,你只需要这样做

  1. 转到你安装phpwtf的位置,在根目录中,然后在控制台中输入
    php vendor/bin/phpwtf review --paths="./vendor/phpwtf/phpwtf/examples/*.php,./vendor/phpwtf/phpwtf/examples/*.js,./vendor/phpwtf/phpwtf/examples/*.html" -r --format=html --output-path="../reports/"
  2. 现在你应该在根目录中看到一个名为reports的目录,其中包含HTML报告

当然,phptwtf脚本支持帮助命令

参数可以写成这样

php vendor/bin/phpwtf.php review --paths="path/.php,path/.js" --format=html --output-path="path/to/reports/" -r -b

这个选项列表不是完整的,并且可能会随时更改。你可以使用帮助或列表命令,以获得任何时间更新的信息。另外,请注意,由于它们都是选项,所以它们可以放在任何顺序。

--input-path    -p      Paths to scan for sources, 
                            ie: "/some/path/*.php,/some/other/path/*.js"
                            Default to "/". Becareful, relative path are resolved 
                            from either vendor folder or root folder if you 
                            have not installed phpwtf with composer.

--recursive     -r      If set, the paths will be scanned recursively. Defaults to *FALSE*

--format        -f      by default xml, can be set to html, html+stats, xml+stats
                            the xml is a simple xml with files, and errors
                            the html is a set of pages per file, with the errors
                            reported + stats stats will just ouput statistics
                            about the nb of WTF, etc
                            finally you can combine output format by using "+"

--output-path   -o      defaults to ./reports/
                            the directory where you want your reports to be written

--skip-error    -s      if set, errors will not stop the parsing.

--bench         -b      To display timings.

还有什么?

接受贡献(Jenkins集成、代码探索、图表、更好的解析...):

徽标和favicon由David Smith提供,并受phpwtf项目的MIT许可证保护。