iodigital-com/php-code-sniffer-standard 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

iodigital-com/php-code-sniffer-standard

Composer 安装命令:

composer require iodigital-com/php-code-sniffer-standard

包简介

iO PHP_CodeSniffer Standard

README 文档

README

Extending the default PHP_CodeSniffer with iO rules

Installation

Require the package:

composer require --dev iodigital-com/php-code-sniffer-standard

Setup

Create a phpcs.xml-file in the root of your project, and include the default iO ruleset:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
    <arg name="cache"/>

    <!-- include root folder of project , change to your framework requirements -->
    <file>.</file>
    <!-- exclude paths -->
    <exclude-pattern>./src/Migrations</exclude-pattern>
    <exclude-pattern>./vendor</exclude-pattern>
    <exclude-pattern>./local-repo</exclude-pattern>

    <!-- include all rules in iO ruleset -->
    <rule ref="IO"/>
    <rule ref="YourFramework"/> <!-- include your framework standards -->
    
    <!-- Configure minimum supported PHP version (used by PHP_CodeSniffer and Slevomat sniffs) -->
    <config name="php_version" value="80100"/>
    <!-- Configure PHP version or range of PHP versions (used by PHPCompatibility sniffs) -->
    <config name="testVersion" value="8.2-8.5"/>
</ruleset>

Modify the excluded paths and PHP versions and optionally include custom rulesets for your project.

Usage

Since you now have a phpcs.xml file in the root of your project, you can run the default phpcs command: vendor/bin/phpcs.

Ignoring sniff violations

Sometimes a violation of a sniff cannot be resolved. In this case, the violation should be ignored using the phpcs:ignore and phpcs:disable / phpcs:enable annotations.

In order to do this, please take the following approach:

  1. Ignore only the parts of the file that cause the violation, not the file itself. If it is really the case the file should be ignored, you can use the phpcs:ignoreFile annotation or, better, add an <exclude-pattern> to the ruleset.xml of the project.
  2. Prefer phpcs:ignore over phpcs:disable and phpcs:enable, i.e. use phpcs:ignore when this is possible and when the placement of the phpcs:ignore does not introduce any other sniff violations, use phpcs:disable and phpcs:enable otherwise. Rationale: using phpcs:disable and phpcs:enable might disable more code than initially intended when adding new code or moving existing code, for instance when refactoring code.
  3. Always indicate the exact sniff or sniffs that are going to be ignored, use the complete sniff name, not only the sniff group. So for instance use phpcs:ignore Squiz.WhiteSpace.FunctionSpacing.BeforeFirst, Squiz.WhiteSpace.FunctionSpacing.AfterLast instead of phpcs:ignore Squiz.WhiteSpace.FunctionSpacing or phpcs:ignore without any arguments.
  4. Prefer placing the phpcs:ignore annotation on a separate line before the violation over placing it on the line of the violation itself. Rationale: when ignoring multiple sniffs, the phpcs:ignore annotation can quickly exceed the line length limit; this is not checked when the phpcs:ignore annotation is placed on a separate line before the violation, but it is checked when the phpcs:ignore annotation is placed on the line of the violation itself.
  5. Add an explanation why the sniff is ignored using -- followed by a short explanation.

Example:

try {
    $this->logger->log(LogLevel::INFO, new DateTimeImmutable());
//phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch -- DateTimeImmutable creation cannot fail in this case
} catch (Exception $exception) {
}

Contributing

If you want to contribute, create a merge request with one sniff per merge request. Please provide an example in the description of what the sniff is about with a good and bad code snippet.

Note: Adding new phpcs rules to this package must result in a major version update!

iodigital-com/php-code-sniffer-standard 适用场景与选型建议

iodigital-com/php-code-sniffer-standard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29.19k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2023 年 06 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 iodigital-com/php-code-sniffer-standard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 iodigital-com/php-code-sniffer-standard 我们能提供哪些服务?
定制开发 / 二次开发

基于 iodigital-com/php-code-sniffer-standard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 4
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-23