silverstripe / moduleratings
一个提供模块代码质量评分的库
Requires
- guzzlehttp/guzzle: ^6
- psr/log: ^1.0
- symfony/console: ~3.0|~4.0
- symfony/finder: ~3.0|~4.0
- symfony/yaml: ~3.0|~4.0
Requires (Dev)
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^3.0
README
本模块提供了一套检查套件,以及一系列自动化检查,可以对 SilverStripe 模块进行运行以确定“质量评分”。
此库可以安装到使用 Composer 的 SilverStripe 3 或 4 项目中。
安装
如果您想使用其公共 API,则可以使用 Composer 安装此库
composer require silverstripe/moduleratings
您还可以安装 silverstripe/moduleratings-plugin Composer 插件,该插件将提供您可以在本地运行的 Composer 命令,以检查模块质量评分。请参阅该模块中的说明以获取更多关于使用它的信息。
要求
- symfony/finder 3 或 4
- symfony/yaml 3 或 4
注意:如果在安装过程中与任何 symfony 组件(如果使用 Composer 插件)发生冲突,您可能需要手动要求这些包中一个或两个的旧版本,例如。
composer require symfony/yaml ~3.0
composer require symfony/console ~3.0
使用 API
要创建检查套件,请使用 SilverStripe\ModuleRatings\CheckSuite
类。您需要提供要检查的模块代码的目录路径,以及可选的模块 GitHub 仓库的缩写(注意:目前仅支持 GitHub)。提供仓库缩写将启用检查,这些检查将查看外部持续集成系统 API 以确定质量指标(例如 Travis、Scrutinizer)。
$checkSuite = new \SilverStripe\ModuleRatings\CheckSuite(); $checkSuite ->setModuleRoot('/path/to/silverstripe/framework') ->setRepositorySlug('silverstripe/silverstripe-framework'); $checkSuite->run(); echo 'Framework has scored ' . $checkSuite->getScore() . ' out of 100 points. Details:', PHP_EOL; print_r($checkSuite->getCheckDetails());
从 CheckSuite::getCheckDetails
返回的数据是一个数组,其结构如下所示(注意示例是 JSON 编码的)
{ "good_code_coverage": { "description": "Has a \"good\" level of code coverage (greater than 40%, requires slug)", "points": 5, "maximum": 5 }, "has_code_of_conduct_file": { "description": "Has a code of conduct file", "points": 2, "maximum": 2 }, "coding_standards": { "description": "The PHP code in this module passes the SilverStripe lint rules (mostly PSR-2)", "points": 0, "maximum": 10 } }
可用的检查
- 良好的代码覆盖率(>= 40%)(通过 Scrutinizer CI 或 Codecov.io)
- 优秀的代码覆盖率(>= 75%)(通过 Scrutinizer CI 或 Codecov.io)
- PHP 代码位于“code”或“src”文件夹中
- PHP 代码通过了 PSR-2 标准的 linting 检查(phpcs.xml.dist 存储在
src/Check/CodingStandardCheck
中以供参考) - 存在贡献指南文件
- 有文档
- EditorConfig 配置文件存在
- .gitattributes 文件存在
- 存在许可文件
- 仓库有一个自述文件
- Scrutinizer CI 已配置,并且有“良好”的质量评分(>= 6.5/10)
- Travis CI 或 CircleCI 中有一个已配置并且最后一次构建成功
注册的检查定义在 config.yml
中,并指定了每个检查通过时获得的分数。
注意事项
请注意以下注意事项/陷阱/待办事项
- 代码仓库必须存在于 GitHub 上才能使外部 API 检查正常工作
谢谢!
衷心感谢 Chris Pitt,他最初编写了 Helpful Robot,这是此库的灵感来源。
此库中的检查受到了原始 Helpful Robot 检查的强烈启发,并且旨在与 SilverStripe 商业支持模块标准 匹配。
没有有用的机器人,今天的SilverStripe社区看起来会乱得多!