定制 keboola/coding-standard 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

keboola/coding-standard

最新稳定版本:16.0.0

Composer 安装命令:

composer require keboola/coding-standard

包简介

Keboola coding standard

README 文档

README

Versioning

  • patch versions may only weaken the checks if a bug in a sniff is found
  • minor versions may only update underlying coding standards with bugfixes
  • major versions may introduce new sniffs, thus causing previously good builds to fail

So you should usually be fine with composer's default ^major.minor

Installation

  • install via composer
composer require --dev keboola/coding-standard
  • copy example/phpcs.xml to your project root directory.
  • now you can check your src and tests directory using
vendor/bin/phpcs src tests
  • create ecs.php in your project root directory with the following content:
<?php

return ECSConfig::configure()->withSets([
    __DIR__ . 'vendor/keboola/coding-standard/src/ruleset.php',
]);
  • command vendor/bin/ecs src/ will now run the checks

  • command vendor/bin/ecs --fix src/ will now run the checks with automatic fixes

  • add phpcs & ecs script to composer.json

{
...
    "scripts": {
        "phpcs": "phpcs -n --extensions=php .",
        "ecs": "ecs"
    }
}

Usage

composer phpcs OR composer ecs

Using standard on legacy projects

If fixing the violations is too complex, you can exclude the respective sniffs.

First you need to know which sniff is causing the violation.

composer phpcs -- -s

This will dump the sniff name along with the violation.

phpcs -n --extensions=php . "-s"

FILE: W:\keboola\http-extractor\src\Config.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 11 | ERROR | Method \Keboola\HttpExtractor\Config::getBaseUrl() does not
    |       | have return type hint nor @return annotation for its return
    |       | value.
    |       | (SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint)
----------------------------------------------------------------------

Then add the sniff to excludes in your phpcs.xml

<?xml version="1.0"?>
<ruleset name="Custom">
    <rule ref="vendor/keboola/coding-standard/ruleset.xml">
		<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint" />
	</rule>
</ruleset>

Repeat until there are no violations.

You may take note of fixable violations and separate them visually in the file, possibly with <!-- Fixable violations below -->. That way anyone can remove one exclusion at a time, let phpcbf fix the violation, review the result and submit a PR with a fix. This will improve the chances of fixing the violations in the future.

License

MIT licensed, see LICENSE file.

统计信息

  • 总下载量: 407.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 87
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 16
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-26