unionofrad / li3_quality
此li₃插件为您的工具集添加了代码质量保证。
Requires
- php: >=5.3
- composer/installers: 1.*
- unionofrad/lithium: 1.0.*
This package is auto-updated.
Last update: 2024-09-12 03:38:36 UTC
README
此li₃插件为您的工具集添加了代码质量保证。
主要功能
- 检测编码标准违规。
- 查找弱或未测试的类和方法。
- 无外部依赖。
- 颜色高亮。
- 集成到Lithium测试仪表板。
- 无需烦恼即可在Windows上运行。
- 快捷方式以简化您的工作流程。
安装
首选的安装方法是使用composer。您可以通过以下方式将库添加为依赖项
composer require unionofrad/li3_quality
li₃库必须在您的应用程序引导阶段注册,因为它们使用不同的(更快的)自动加载器。
Libraries::add('li3_quality')
如果您打开测试仪表板(在浏览器中的 /test
下),您应该有一个额外的 语法
按钮,可以直接在浏览器中检查文件。
用法:“语法”命令
如果您只通过 li3 syntax
运行它,它将对您的 app
库运行所有规则。
$ li3 syntax --verbose path/to/code -------------------- Lithium Syntax Check -------------------- Performing 16 rules on 6 classes. [FAIL] app\models\Authors Line Position Violation ---- -------- --------- 7 1 Trailing whitespace found [OK] app\models\Groups [OK] app\models\Posts [FAIL] app\controllers\HelloWorldController Line Position Violation ---- -------- --------- 17 - Function "to_string" is not in camelBack style 21 - Function "to_json" is not in camelBack style 24 1 Trailing whitespace found [FAIL] app\controllers\PagesController Line Position Violation ---- -------- --------- 32 1 Trailing whitespace found 34 1 Trailing whitespace found 28 - Protected Method "view" does not start with "_" 33 - Protected Method "foobar" does not start with "_"
用法:“修复”命令
修复命令有助于将代码迁移到新版本。它将重写现有的源代码文件并就地更新它们。请注意,使用此命令时,应使用版本控制系统,因为结果可能并不总是您期望的100%。
$ li3 fix --verbose path/to/code
自定义规则和规则集
基于规则的命令(语法和修复)仅适用于规则集配置文件。如果没有通过 --config=<FILE>
选项提供,则这些命令将回退到使用 config/syntax.json
和 config/fix.json
中的默认配置文件。
自定义规则必须创建为例如 <your library>/extensions/qa/rules/{syntax,fix}/YourCustomRule.php
。
GIT预提交钩子
此预提交钩子基于 .git/hooks/pre-commit.sample
中的示例。将示例脚本复制到 /path/to/project/.git/hooks/pre-commit
并使其可执行。然后,将脚本中的代码替换为以下代码,并调整插件和li3命令的路径。
cd /path/to/project
cp .git/hooks/pre-commit.sample .git/hooks/pre-commit
chmod a+x .git/hooks/pre-commit
现在将以下代码添加到 .git/hooks/pre-commit 并调整 APP
和 LI3
值。
#!/bin/sh APP=/path/to/li3_quality_enabled/app/ LI3=/path/to/lithium/libraries/lithium/console/li3 if git-rev-parse --verify HEAD >/dev/null 2>&1 then AGAINST=HEAD else # Initial commit: diff against an empty tree object AGAINST=4b825dc642cb6eb9a060e54bf8d69288fbee4904 fi EXIT_STATUS=0 PROJECT=`pwd` for FILE in `git diff-index --cached --name-only --diff-filter=AM ${AGAINST}` do cd ${APP} && ${LI3} syntax ${PROJECT}/${FILE} test $? != 0 && EXIT_STATUS=1 done exit ${EXIT_STATUS}
现在在提交每个文件时都会检查语法。如果检查失败,则中止提交。如果您不想在提交时运行钩子,请将 --no-verify
选项传递给git commit。
用法:“覆盖率”命令
使用 li3 coverage
您可以了解您的类被测试覆盖得有多好。这使用了某些 xdebug
功能,因此请确保已安装它。
$ li3 quality coverage --------------------- Lithium Code Coverage --------------------- Checking coverage on 6 classes. no test | n/a | app\models\Authors no test | n/a | app\models\Groups no test | n/a | app\models\Posts no test | n/a | app\controllers\HelloWorldController no test | n/a | app\controllers\PagesController no test | n/a | app\controllers\PostsController
您还可以重用 --library
参数。此外,此命令提供了可选的 --threshold
参数,仅显示低于给定数量的覆盖率。默认值为100,因此将显示所有类。如果您在shell中启用了颜色(在Windows上可能不会),则类将根据Lithium框架的覆盖策略进行着色(0%或没有测试为红色,85%或更高为绿色,其余为黄色)。
版权与许可
版权所有 2011 Union of RAD。保留所有权利。此库根据BSD 3-Clause许可条款分发。完整的许可文本可以在 LICENSE.txt 文件中找到。