karriere / code-quality
可以通过 Composer 运行的代码质量脚本。
Requires
- php: >=7.1
- dg/bypass-finals: ^1.1
- friends-of-phpspec/phpspec-code-coverage: ^4.3
- karriere/phpspec-matchers: ^3.0
- phpmd/phpmd: ^2.6
- phpspec/phpspec: ^5.1 || ^6.0
- squizlabs/php_codesniffer: ^3.3
- symfony/console: ^3.2 || ^4.0
- symfony/process: ^3.2 || ^4.0
Requires (Dev)
- composer/composer: ^1.6
- dev-master
- v5.1.0
- v5.0.0
- v4.2.0
- v4.1.0
- v4.0.0
- v4.0.0-beta.1
- v3.0.0
- v2.0.0
- v2.0.0-beta.1
- v2.0.0-alpha.1
- v1.3.1
- v1.3.0
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- v0.2.0
- v0.1.0
- dev-dev/deprecate-package
- dev-feature/ignore-final-classes
- dev-dev/coverage-extension
- dev-bugfix/handle-phpcbf-exit-codes
This package is auto-updated.
Last update: 2020-12-14 11:11:59 UTC
README
❗️ 此包不再积极开发。 ❗
PHP 包的代码质量
此包提供可以通过 Composer 运行的代码质量脚本。
这些脚本也适用于 Jenkins 等持续集成 (CI) 服务器。
使用的包
phpspec/phpspec
用于测试(SpecBDD)代码。
必须在根目录中配置 phpspec.yml
文件。
我们使用 leanphp/phpspec-code-coverage
扩展来生成覆盖率报告。
此扩展需要在根目录中有一个 phpspec-coverage.yml
文件,并且启用 Xdebug。
squizlabs/PHP_CodeSniffer
目前用于检查(linting)和修复代码。
检查 src
目录中的所有文件。
phpmd/phpmd
用于检测混乱。
在 src
目录中的所有文件上运行定义的规则集(config/phpmd.xml
)。
安装
运行 composer require --dev karriere/code-quality
来安装此包。
安装后,将所需的脚本插入到 composer.json
中。
{ "scripts": { "test": "Karriere\\CodeQuality\\SpecificationTest::run", "lint": "Karriere\\CodeQuality\\CodeStyleChecker::run", "fix": "Karriere\\CodeQuality\\CodeStyleFixer::run", "coverage": "Karriere\\CodeQuality\\CodeCoverage::run", "md": "Karriere\\CodeQuality\\MessDetector::run" } }
用法
您可以运行脚本如下:composer {script} -- {options}
。
如果您在 Windows 上使用 Git-Shell(或在 Windows 的 Intellij Terminal 中的 Git-Shell),请按如下方式调用脚本:
composer.bat {script}
。否则颜色将不会显示。
您可以通过添加 --notty
标志来禁用 TTY
(Jenkins 所需)。
在 Windows 平台上自动禁用。
composer {script} -- --env=jenkins --notty
脚本
test
Usage:
test [--] [options]
Options:
--fail Exit with 1 if tests fail.
--notty Disable TTY.
--ptimeout Set process timeout (defaults to 60 seconds).
-v --verbose Increase the verbosity of messages.
coverage
Usage:
coverage [--] [options]
Options:
--env Specifiy the environment. Possible values:
'local': prints output on command-line.
'jenkins': generates a JUnit report file.
--notty Disable TTY.
--ptimeout Set process timeout (defaults to 60 seconds).
lint
Usage:
lint [--] [options]
Options:
--env Specifiy the environment. Possible values:
'local': prints output on command-line.
'jenkins': generates a checkstyle report file.
--fail Exit with 1 if linting fails.
--notty Disable TTY.
--ptimeout Set process timeout (defaults to 60 seconds).
md
Usage:
lint [--] [options]
Options:
--env Specifiy the environment. Possible values:
'local': prints output on command-line.
'jenkins': generates a xml report file.
--notty Disable TTY.
--ptimeout Set process timeout (defaults to 60 seconds).
fix
Usage:
fix [--] [options]
Options:
--notty Disable TTY.
--ptimeout Set process timeout (defaults to 60 seconds).
使用自定义匹配器
此包集成了 karriere/phpspec-matchers。为了使用本包中定义的自定义匹配器,请将扩展配置包含在您的 phpspec.yml
文件中。
常见问题解答 (FAQ)
为什么我必须提供两个 phpspec 配置文件?
代码覆盖率扩展会使 phpspec 测试变慢,所以我们将其排除在正常配置文件之外。保持测试速度快!
如何增加 test
脚本输出的详细程度?
运行 composer test -- -v
。