juliangut/php-cs-fixer-custom-fixers

PHP CS Fixer 自定义修复器

1.1.1 2024-08-22 13:19 UTC

README

PHP version Latest Version License

Total Downloads Monthly Downloads

php-cs-fixer-custom-fixers

PHP-CS-Fixer 提供自定义修复器

安装

Composer

composer require --dev juliangut/php-cs-fixer-custom-fixers

使用方法

在 PHP-CS-Fixer 配置中注册自定义修复器

 <?php

 use Jgut\PhpCsFixerCustomFixers\Fixers;
 use Jgut\PhpCsFixerCustomFixers\Fixer\Comment\LeadingUppercaseCommentFixer;
 use Jgut\PhpCsFixerCustomFixers\Fixer\Comment\PhpdocLeadingUppercaseSummaryFixer;
 use Jgut\PhpCsFixerCustomFixers\Fixer\LanguageConstruct\FloatLeadingZeroFixer;
 use PhpCsFixer\Config;

 return (new Config())
+    ->registerCustomFixers(new Fixers())
     ->setRules([
         '@PSR2' => true,
         // ...,
+        LeadingUppercaseCommentFixer::name() => true,
+        PhpdocLeadingUppercaseSummaryFixer::name() => true,
+        FloatLeadingZeroFixer::name() => true,
     ]);

修复器

语言构造

FloatLeadingZeroFixer

浮点值是否应该或不应该有前导零

 <?php
 
 class Foo
 {
-    private float $value = .5;
+    private float $value = 0.5;
 }
配置

leading_zero (字符串), 应该 添加 或应该 移除 前导零

注释

LeadingUppercaseCommentFixer

注释应以首字母大写开头

 <?php

-// this is a comment
+// This is a comment

 /*
- * this is a block comment
+ * This is a block comment
  */

PhpdocLeadingUppercaseSummaryFixer

文档块摘要应以首字母大写开头

 <?php

 class Foo
 {
     /**
-     * this is a docblock summary.
+     * This is a docblock summary.
      */
     public function bar()
     {
     }
 }

贡献

发现了一个错误或有一个功能请求? 请打开一个新问题。在提交之前,请先查看现有的问题。

查看文件 CONTRIBUTING.md

许可证

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