定制 eventjet/coding-standard 二次开发

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

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

eventjet/coding-standard

Composer 安装命令:

composer require eventjet/coding-standard

包简介

Eventjet Coding Standard

README 文档

README

Scope: formatting, not linting

This package historically included rules that overlap with what static analyzers (PHPStan, Psalm) already catch. Going forward we will not add such rules, and we will progressively disable existing ones — if PHPStan or Psalm flag a pattern, a CS rule for it is duplicate work.

Treat this package as a formatter/style standard only. To get the full benefit, run a static analyzer alongside it; PHP-CS-Fixer and PHPCS are not a substitute for PHPStan or Psalm.

PHP-CS-Fixer

Basic Usage:

Add the following .php-cs-fixer.dist.php file to your project's root:

<?php

declare(strict_types=1);

use Eventjet\CodingStandard\PhpCsFixer\Config;

return Config::basic();

This will create a basic configuration with a Finder that includes everything in . and excludes vendor. If you need a more granular directory specification, you can pass a custom Finder:

<?php

declare(strict_types=1);

use Eventjet\CodingStandard\PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()->in(['features', 'module', 'tests'])->exclude('tests/fixtures');
return Config::basic($finder);

More strict rules:

To use the strict rules, use the strict method::

<?php

declare(strict_types=1);

use Eventjet\CodingStandard\PhpCsFixer\Config;

return Config::strict();

The strict rules enforce a union syntax for nullable types, a certain method order and trailing commas everywhere. See the file for details.

PHPCS

Basic Usage:

Add the following phpcs.xml file to your project's root:

<?xml version="1.0"?>
<ruleset>
    <rule ref="Eventjet"/>

    <file>src</file>
    <file>tests</file>
</ruleset>

More strict rules:

There is also a more strict ruleset which forces type hints and return types to be set.

This sniff can be problematic: If you implement interfaces or have your own interfaces which don't have parameter type hints and return types set or if you are on legacy code, enforcing this sniff would lead to a BC break. This sniff is also set to phpcs-only, so phpcbf won't fix errors automatically.

To use this ruleset, just use the corresponding rule name in your phpcs rule ref instead of the default one:

<?xml version="1.0"?>
<ruleset>
    <rule ref="EventjetStrict"/>

    <file>src</file>
    <file>tests</file>
</ruleset>

Excluding sniffs:

For certain files:

To exclude a sniff for a certain set of files, reference the rule explicitly and add an exclude pattern:

<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint">
    <exclude-pattern>*Interface.php</exclude-pattern>
</rule>

Suppressing sniffs locally

To suppress a sniff directly in the code, use the @phpcsSuppress annotation:

/**
 * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
 * @param int $bar
 */
public function foo($bar = 0): int
{
}

More info on this can be found here.

Exclude a whole sniff:

It is also possible to exclude a sniff completely:

<?xml version="1.0"?>
<ruleset>
    <rule ref="Eventjet">
        <exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
    </rule>

    <file>src</file>
    <file>tests</file>
</ruleset>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固