juliangut/php-codesniffer-custom-sniffs

PHP_CodeSniffer 自定义嗅探器

资助包维护!
juliangut

安装次数: 5,517

依赖关系: 1

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:phpcodesniffer-standard

1.2 2024-03-05 14:30 UTC

This package is auto-updated.

Last update: 2024-09-05 21:23:56 UTC


README

PHP version Latest Version License

Total Downloads Monthly Downloads

php-codesniffer-custom-sniffs

PHP_CodeSniffer 定制的嗅探器

安装

Composer

composer require --dev juliangut/php-codesniffer-custom-sniffs

使用方法

建议安装 dealerdirect/phpcodesniffer-composer-installer 以避免在规则集定义文件中声明路径

完整规则集

<?xml version="1.0"?>
<ruleset name="MyProject">
    <rule ref="JgutCodingStandard"/>

    <!-- if dealerdirect/phpcodesniffer-composer-installer is not installed-->
    <rule ref="vendor/juliangut/php-codesniffer-custom-sniffs/src/JgutCodingStandard/ruleset.xml" /><!-- path relative to your ruleset definition file -->
</ruleset>

仅某些嗅探器

<?xml version="1.0"?>
<ruleset name="MyProject">
    <!-- if dealerdirect/phpcodesniffer-composer-installer is not installed-->
    <config name="installed_paths" value="../../juliangut/php-codesniffer-custom-sniffs"/><!-- path relative to PHPCS source location on vendor directory -->

    <rule ref="JgutCodingStandard.NamingConventions.CamelCapsFunctionName" />
    <rule ref="JgutCodingStandard.NamingConventions.CamelCapsVariableName">
        <properties>
            <property name="strict" value="false" />
        </properties>
    </rule>
</ruleset>

嗅探器

代码分析

EmptyStatementSniff

不应有空语句

 <?php
 
 if (\PHP_VERSION_ID >= 80_000) {
+    echo 'do something';
 }
配置

catchIgnoreComment (字符串),允许空捕获语句。通过添加注释包含此变量的内容,默认设置为 @ignoreException

 <?php
 
 try {
     curl_close(null);
 } catch (\Throwable $exception) {
+    // @ignoreException
 }

命名约定

CamelCapsFunctionNameSniff

函数和方法名称应使用驼峰命名法

 <?php
 
 class Foo
 {
-    public function max_length(): int
+    public function maxLength(): int
     {
     }
 }
配置

strict (布尔值),设置为 false 以允许连续两个大写字母(驼峰命名法不允许连续两个大写字母)

CamelCapsVariableNameSniff

变量和属性名称应使用非驼峰命名法

 <?php
 
 class Foo
 {
-    private bool $max_length = 255;
+    private bool $maxLength = 255;
 }
配置

strict (布尔值),设置为 false 以允许连续两个大写字母(驼峰命名法不允许连续两个大写字母)

贡献

发现了一个错误或有一个功能请求?请 创建一个新的问题。在创建之前查看现有的问题。

查看 CONTRIBUTING.md 文件

许可

有关许可条款的副本,请参阅源代码中包含的 LICENSE 文件。