配置特定于 LoVullo Associates 编码标准的 QA 和开发工具。该软件包与lovullo/phpqatools
相结合,旨在成为新 PHP 项目的基础。
只需在项目的composer.json
中需要它
"require-dev" : {
"lovullo/phpqaconfig" : " @stable "
}
或者
$ composer require --dev lovullo/phpqaconfig
在项目根目录中创建一个包含以下内容的build.xml
文件:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >
在项目根目录中创建一个phpunit.xml
文件,其中包含以下内容:
<? xml version = " 1.0 " encoding = " UTF-8 " ?>
< phpunit verbose = " true " >
< testsuites >
< testsuite name = " ProjectName " >
< directory suffix = " Test.php " >tests/</ directory >
</ testsuite >
</ testsuites >
< logging >
< log type = " coverage-html " target = " build/coverage " />
< log type = " coverage-clover " target = " build/logs/clover.xml " />
< log type = " coverage-crap4j " target = " build/logs/crap4j.xml " />
< log type = " junit " target = " build/logs/junit.xml " logIncompleteSkipped = " false " />
</ logging >
</ phpunit >
如果您在其他地方已有 PHPUnit 配置,请参阅下面的“自定义”部分。
开发时,使用以下 ant 目标:
例如:
$ ant phpcs phpmd phpcpd
配置持续集成(即 Jenkins)时, composer
必须下载并安装此存储库,然后才能运行ant
任务。使用以下命令向 Jenkins 添加“执行 Shell”构建步骤:
$ composer install -o
接下来,添加具有以下目标的“Invoke Ant”构建步骤:
build-qa
这将运行check_mergeconflicts
、 phplint
、 phpunit
、 phpcs-ci
、 pdepend
、 phpmd-ci
、 phpcpd-ci
、 phploc-ci
和phpdox
。
对于需要快速运行并且只需要最少数量的 QA 检查的作业,请改为运行以下目标:
build-quick
这将运行check_mergeconflicts
、 phplint
和phpunit
。
根据您的特定项目的情况,将其他构建目标添加到您的build.xml
文件中。
包含的build.xml
假定所有 QA 工具都安装到./vendor/bin
中。如果它们安装在其他地方,请为其位置提供一个toolsdir
属性:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " toolsdir " value = " ${basedir}/bin/ " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >
默认情况下,包含的build.xml
对项目中的所有 PHP 文件运行php -l
,项目根目录中的vendor/
目录除外。您可以使用phplintignore
属性覆盖此设置:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phplintignore " value = " components/**/*,vendor/**/* " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >
默认情况下,包含的build.xml
假定在与其自身相同的目录中有一个phpunit.xml
文件。如果您已经有位于其他位置的phpunit.xml
文件,您可以按如下方式覆盖配置:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpunitconfig " value = " ${basedir}/app/ " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >
您可以通过指定phpcsignore
属性来自定义在phpcs
检查中忽略的文件:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpcsignore " value = " app/,bin/,vendor/,web/ " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >
默认情况下,只有vendor
目录被排除在检查之外。
您可以通过覆盖phpcsstandard
属性来更改 PHP_CodeSniffer 标准使用的内容:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpcsstandard " value = " PSR1,PSR2 " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >
您可以通过指定phpmdignore
属性来自定义在phpmd
检查中忽略的文件:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpmdignore " value = " app,bin,vendor,web " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >
默认情况下,只有vendor
目录被排除在检查之外。
您可以通过指定phpcpdignore
属性来自定义在phpcpd
检查中忽略的文件:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " phpcpdignore " value = " --exclude vendor --exclude app " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >
默认情况下,只有vendor
目录被排除在检查之外。
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< phpdox xmlns = " http://xml.phpdox.net/config " silent = " true " >
< bootstrap />
< project name = " phpdox " source = " ${basedir}/src " workdir = " ${basedir}/build/phpdox/xml " >
< collector publiconly = " false " backend = " parser " >
< include mask = " *.php " />
< inheritance resolve = " true " />
</ collector >
< generator output = " ${basedir}/build/docs " >
< enrich base = " ${basedir}/build " >
< source type = " build " />
< source type = " phploc " >
< file name = " logs/phploc.xml " />
</ source >
< source type = " git " >
< git binary = " git " />
< history enabled = " true " limit = " 15 " cache = " ${phpDox.project.workdir}/gitlog.xml " />
</ source >
< source type = " checkstyle " >
< file name = " logs/checkstyle.xml " />
</ source >
< source type = " phpunit " >
< file name = " logs/phpunit " />
</ source >
< source type = " pmd " >
< file name = " logs/pmd.xml " />
</ source >
</ enrich >
< build engine = " html " enabled = " true " output = " html " >
< template dir = " ${phpDox.home}/templates/html " />
< file extension = " html " />
</ build >
</ generator >
</ project >
</ phpdox >
如果您不希望为项目运行某些 QA 工具,请在包含基础build.xml
文件之前添加以下一项或多项disable
属性:
<? xml version = " 1.0 " encoding = " utf-8 " ?>
< project name = " project-name " >
< property name = " disable-phpunit " value = " true " />
< property name = " disable-pdepend " value = " true " />
< property name = " disable-phpmd " value = " true " />
< property name = " disable-phpcs " value = " true " />
< property name = " disable-phpcpd " value = " true " />
< import file = " ${basedir}/vendor/lovullo/phpqaconfig/build.xml " />
</ project >