karriere/code-quality

此包已被废弃,不再维护。未建议替代包。

可以通过 Composer 运行的代码质量脚本。

v5.1.0 2020-02-21 07:37 UTC

README

687474703a2f2f7777772e6b617272696572652e61742f696d616765732f6c61796f75742f6b61746c6f676f2e737667     Build Status Code Style

❗️ 此包不再积极开发。 ❗

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