michael34435/php-ranker

使用 phpcs/phpmd/phpcpd 违规报告从项目中抓取 GPA

1.0.3 2017-01-17 10:04 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:35:38 UTC


README

Build Status Code Climate

php-ranker 是什么?

php-ranker 是一个基于命令行的解析器,用于解析由 phpmdphpcsphpcpd 生成的 xml 格式报告文件。
php-ranker 计算的所有分数都是基于 codeclimate 的,除了来自 phpcpd 的重复报告,因为 codeclimate 使用他们自己的分析工具(flay)来识别代码块是否相同或类似,而 phpcpd 不能做到这一点。

php-ranker 使用哪些指标?

php-ranker 考虑了三个维度。

  • Checkstyle
    • 包括 PSR-2 标准等等的所有内容
  • PMD
    • Checkstyle、复杂度和代码大小
  • Dry
    • 使用 phpcpd 而不是 flay 检测到的重复代码

如何计算等级?

GPA(平均成绩点)是什么?

所有成绩都遵循 GPA(平均成绩点)的概念,这是美国学校用来确定你在平均意义上的好坏的一种方法,大多数都是 4 点规则。

如何计算它?

一般来说,GPA 是 四点,这意味着在这个科目中,最优秀的学生得到 4 点,而最差的学生得到 0 点。
然后我们将得到一个人的平均分数。
像这个图表

例如,有一个学生得到了两个 A(代表 4 点)和一个 B(代表 3 点),我们将得到一个公式 -> (2 x 4 + 3) / (2 + 1) = 3.67
3.67 是这个学生的最终分数。

php-ranker 如何得到文件分数

您必须在项目中添加一个名为 .php-ranker 的配置文件(见 .php-ranker.example),并使用 composer require php-ranker
然后 php-ranker 将读取您的配置文件并将它们全局化以比较 phpcsphpmdphpcpd 的违规报告。
最后,php-ranker 给每个文件分配以下分数。(所有规则均遵循 codeclimate

因此,您的文件将获得总分,然后 php-ranker 最终将其转换为字母等级。

php-ranker 如何得到总 GPA

所有 GPA 都基于文件大小。
例如,php-ranker 找到三个文件

Foo.php A 等级代表 4 点
FooBar.php A 等级也代表 4 点
Bar.php 太糟糕了,得不到分数,得 0 点。

我们可以找到一个公式 -> (4 x 100 + 4 x 200 + 0 x 1000) / (200 + 100 + 1000) = 0.93

0.93 是这些文件的总 GPA 分数。

如何使用 php-ranker

安装

Composer

composer require michael34435/php-ranker

Phar

curl -LOk https://github.com/michael34435/php-ranker/raw/master/build/php-ranker
chmod +x php-ranker
mv php-ranker /usr/bin/php-ranker

用法

./vendor/bin/php-ranker
  • --pmd-report - phpmd 违规报告路径(xml)
  • --dry-report - phpcpd 违规报告路径(xml)
  • --checkstyle-report - phpcs 违规报告(xml)
  • --export-dir - 您想存储 GPA 报告 html 的路径

注意

版本 0.010.02 仅支持 jenkins 报告,我建议您尽快升级到 1.0.0dev-master