定制 dcandido/code-sniffer 二次开发

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

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

dcandido/code-sniffer

最新稳定版本:v1.6.0

Composer 安装命令:

composer require dcandido/code-sniffer

包简介

CodeSniffer.

README 文档

README

Table of contents

Requirements

How to install

composer require dcandido/quality-tools --dev

How to use

Enabling the rules

Add it to your project phpcs.xml ruleset:

<?xml version="1.0"?>
<ruleset name="IMSRuleset">
  <description>The coding standard for Project.</description>

  <rule ref="./vendor/dcandido/code-sniffer/ruleset.xml"/>

  <file>app</file>
  <file>bootstrap</file>

  <exclude-pattern>bootstrap/cache/*</exclude-pattern>
  <exclude-pattern>tests/Unit/*</exclude-pattern>
  <exclude-pattern>resources</exclude-pattern>
  <exclude-pattern>bootstrap/autoload.php</exclude-pattern>
  <exclude-pattern>*/migrations/*</exclude-pattern>
  <exclude-pattern>*/seeds/*</exclude-pattern>
  <exclude-pattern>vendor/*</exclude-pattern>
  <exclude-pattern>public/*</exclude-pattern>
  <exclude-pattern>*.js</exclude-pattern>

  <!-- Show progression -->
  <arg value="pv"/> <!-- p for progress, s to see list for each gitblame author, v to see authors with no violations, s include source codes in the report -->
  <arg name="report" value="summary"/><!-- summary, gitblame, source -->
  <arg name="colors"/>
</ruleset>

Usage

Run Command:

./vendor/bin/phpcs

If you have errors, you will see the following:

$ phpcs 

FILE: /path/to/code/file1.php
--------------------------------------------------------------------------------
FOUND 5 ERROR(S) AFFECTING 5 LINE(S)
--------------------------------------------------------------------------------
  2 | ERROR | Missing file doc comment
 20 | ERROR | PHP keywords must be lowercase; expected "false" but found "FALSE"
 47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
 51 | ERROR | Missing function doc comment
 88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
--------------------------------------------------------------------------------

FILE: /path/to/code/file2.php
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
 21 | ERROR   | PHP keywords must be lowercase; expected "false" but found
    |         | "FALSE"
 21 | WARNING | Equals sign not aligned with surrounding assignments
--------------------------------------------------------------------------------

You can run phpcbf to fix the errors automatically:

./vendor/bin/phpcbf
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
.../path/to/code/file.php                               7      0
.../path/to/code/file2.php                              5      0

Sniffing code in PHPStorm

See PHP Code Sniffer in PhpStorm on how to set up CodeSniffer in PHPStorm.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固