eoneopay/standards

此包已被弃用,不再维护。作者建议使用eonx-com/standards包。

用于对代码库执行EoneoPay编码标准的库

v1.0.2 2019-10-22 01:17 UTC

This package is auto-updated.

Last update: 2019-11-09 03:33:10 UTC


README

此库提供了检查代码库是否符合EoneoPay编码标准的工具。

安装

此库通过composer安装

composer require --dev eoneopay/standards dev-master

要求

此库需要至少PHP 5.6。

兼容工具

如果系统上找到以下包,此库将自动运行。它们可以通过composer安装,或者全局可用,例如通过brew安装。

用途
复制粘贴检测器 检测代码重复
Paratest 并行运行单元测试
PHP CodeSniffer 检查代码风格
PHP CS Fixer 标准化代码风格
PHP Mess Detector 检查编码最佳实践
PHPStan 对代码进行静态分析以检测潜在错误
PHPUnit 运行单元测试
安全检查器 检查项目的依赖项是否存在已知漏洞

推荐扩展

建议您还安装以下PHP扩展。

扩展 用途
Xdebug 计算单元测试的代码覆盖率

检查您的代码库

您可以直接从vendor目录运行es来检查您的代码库,任何已安装的包都将自动运行。

bash vendor/bin/es

默认情况下,应用程序或库的app/src/tests/目录中的任何PHP文件都将进行检查。如果使用更改检测,将尽可能进行部分扫描。

强制进行全面扫描

在使用更改检测时,您可能希望运行全面扫描。您可以通过传递-f标志来强制进行全面扫描。

bash vendor/bin/es -f

配置

您可以通过在应用程序或库的根目录中添加一个standards.cfg文件并调整以下变量来微调配置。

# Comma separated paths to files to check, absolute or relative to working directory
PATHS=app,src,tests

########## CHANGE DETECTION CONFIGURATION ##########
# The primary branch for your repository which feature branches are merged into
CD_PRIMARY_BRANCH=development
# Branches which a full scan of the paths above should be performed
CD_FULL_SCAN_BRANCHES=master,${CD_PRIMARY_BRANCH}

########## PHP COPY/PASTE DETECTOR CONFIGURATION ##########
# Whether or not to run php copy/paste detector, will run if phpcpd binary is found
PHPCPD_ENABLED=true
# A comma seperated list of regexes to exclude from copy/paste detection
PHPCPD_EXCLUDE_REGEX=
# The minimum number of lines which need to be duplicated to count as copy/paste
PHPCPD_MIN_LINES=5
# The minimum number of duplicated tokens within a line to count as copy/paste
PHPCPD_MIN_TOKENS=70

########## PHP CODE SNIFFER CONFIGURATION ##########
# Whether or not to run php code sniffer, will run if phpcs binary is found
PHPCS_ENABLED=true
# The standards to compare code against, will be ignored if phpcs.xml exists
PHPCS_STANDARDS=vendor/eoneopay/standards/php-code-sniffer/EoneoPay
# Whether to show the code sniffs name on report output
PHPCS_SHOW_SNIFF_NAME=true

########## PHP CS FIXER CONFIGURATION ##########
# Whether or not to run php code sniffer, will run if phpcs binary is found
PHPCS_FIXER_ENABLED=true
# Default rules to be used when no .php_cs file exists in the project
PHPCS_FIXER_RULES='@PSR2,trailing_comma_in_multiline_array'

########## PHP MESS DETECTOR CONFIGURATION ##########
# Whether or not to run php mess destector, will run if phpmd binary is found
PHPMD_ENABLED=true
# The rulesets to use to determine issues, will be ignored if phpmd.xml exists
PHPMD_RULESETS=cleancode,codesize,controversial,design,naming,unusedcode

########## PHPSTAN CONFIGURATION ##########
# Whether or not to run phpstan, will run if phpstan binary is found
PHPSTAN_ENABLED=true
# The reporting level, 1 = loose, 7 = strict
PHPSTAN_REPORTING_LEVEL=7

########## PHPUNIT CONFIGURATION ##########
# Whether or not to run phpunit, will run if paratest or phpunit binary is found
PHPUNIT_ENABLED=true
# Whether or not to enable code coverage checks
PHPUNIT_ENABLE_CODE_COVERAGE=true
# The minimum percentage of coverage to have, will be ignored if coverage check is disabled
PHPUNIT_COVERAGE_MINIMUM_LEVEL=90
# The testsuites to run with coverage
PHPUNIT_COVERAGE_TEST_SUITES=
# The path to output junit parseable log file, can be relative, will be ignored if left blank
PHPUNIT_JUNIT_LOG_PATH=
# The directory containing tests, will be ignored it phpunit.xml exists in working directory
PHPUNIT_TEST_DIRECTORY=tests
# The test suites to run, will run all tests if not specified
PHPUNIT_TEST_SUITES=

########## SECURITY CHECKER CONFIGURATION ##########
# Whether or not to run security-checker, will run if security-checker binary is found
SECURITY_CHECKER_ENABLED=true

工具配置

您也可以通过在应用程序或库的根目录中添加配置文件来配置单个工具。

文件名
Paratest phpunit.xml
PHP CodeSniffer phpcs.xml
PHP CS Fixer .php_cs
PHP Mess Detector phpmd.xml
PHPStan phpstan.neon
PHPUnit phpunit.xml