承接 erickskrauch/php-cs-fixer-custom-fixers 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

erickskrauch/php-cs-fixer-custom-fixers

Composer 安装命令:

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

包简介

A set of custom fixers for PHP-CS-Fixer

README 文档

README

A set of custom fixers for PHP-CS-Fixer.

Latest Version on Packagist Total Downloads Software License Build Status

Installation

Run:

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

Then in your configuration file (.php-cs-fixer.php) register fixers and use them:

<?php
return (new \PhpCsFixer\Config())
    ->registerCustomFixers(new \ErickSkrauch\PhpCsFixer\Fixers())
    ->setRules([
        'ErickSkrauch/align_multiline_parameters' => true,
        // See the rest of the fixers below
    ]);

Fixers

Table of contents:

ErickSkrauch/align_multiline_parameters

Forces aligned or not aligned multiline function parameters:

--- Original
+++ New
@@ @@
  function foo(
      string $string,
-     int $index = 0,
-     $arg = 'no type',
-     ...$variadic,
+     int    $index    = 0,
+            $arg      = 'no type',
+         ...$variadic
  ): void {}

Configuration:

  • variables - when set to true, forces variables alignment. On false forces strictly no alignment. You can set it to null to disable touching of variables. Default: true.

  • defaults - when set to true, forces defaults alignment. On false forces strictly no alignment. You can set it to null to disable touching of defaults. Default: false.

ErickSkrauch/blank_line_around_class_body

Ensure that a class body contains one blank line after its definition and before its end:

--- Original
+++ New
@@ @@
  <?php
  class Test {
+
      public function func() {
          $obj = new class extends Foo {
+
              public $prop;
+
          }
      }
+
  }

Configuration:

  • apply_to_anonymous_classes - should this fixer be applied to anonymous classes? If it is set to false, than anonymous classes will be fixed to don't have empty lines around body. Default: true.

  • blank_lines_count - adjusts an amount of the blank lines. Default: 1.

ErickSkrauch/blank_line_before_return

This is extended version of the original blank_line_before_statement fixer. It applies only to return statements and only in cases, when on the current nesting level more than one statements.

--- Original
+++ New
@@ @@
 <?php
 public function foo() {
     $a = 'this';
     $b = 'is';
+
     return "$a $b awesome";
 }

 public function bar() {
     $this->foo();
     return 'okay';
 }

ErickSkrauch/line_break_after_statements

Ensures that there is one blank line above the next statements: if, switch, for, foreach, while, do-while and try-catch-finally.

--- Original
+++ New
@@ @@
 <?php
 $a = 123;
 if ($a === 123) {
     // Do something here
 }
+
 $b = [1, 2, 3];
 foreach ($b as $number) {
     if ($number === 3) {
         echo 'it is three!';
     }
 }
+
 $c = 'next statement';

ErickSkrauch/multiline_if_statement_braces

Ensures that multiline if statement body curly brace placed on the right line.

--- Original
+++ New
@@ @@
 <?php
 if ($condition1 === 123
- && $condition2 = 321) {
+ && $condition2 = 321
+) {
     // Do something here
 }

Configuration:

  • keep_on_own_line - should this place closing bracket on its own line? If it's set to false, than curly bracket will be placed right after the last condition statement. Default: true.

ErickSkrauch/ordered_overrides

Overridden and implemented methods must be sorted in the same order as they are defined in parent classes.

--- Original
+++ New
@@ @@
 <?php
 class Foo implements Serializable {

-    public function unserialize($data) {}
+    public function serialize() {}

-    public function serialize() {}
+    public function unserialize($data) {}

 }

Caveats:

  • This fixer is implemented against the PHP-CS-Fixer principle and relies on runtime, classes autoloading and reflection. If dependencies are missing or the autoloader isn't configured correctly, the fixer will not be able to discover the order of methods in parents.

  • Fixer prioritizes extends and applies implements afterwards. It searches for the deepest parents of classes and takes them as the basis for sorting, ignoring later reordering.

  • This fixer runs BEFORE the ordered_interfaces fixer, so you might need to run PHP-CS-Fixer twice when you're using this fixer to get proper result. See this discussion for more info.

ErickSkrauch/remove_class_name_method_usages (Yii2)

Replaces Yii2 BaseObject::className() usages with native ::class keyword, introduced in PHP 5.5.

--- Original
+++ New
@@ @@
  <?php
  use common\models\User;
  
- $className = User::className();
+ $className = User::class;

erickskrauch/php-cs-fixer-custom-fixers 适用场景与选型建议

erickskrauch/php-cs-fixer-custom-fixers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.37M 次下载、GitHub Stars 达 30, 最近一次更新时间为 2023 年 05 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「dev」 「Code style」 「php-cs-fixer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 erickskrauch/php-cs-fixer-custom-fixers 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.37M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 30
  • 点击次数: 17
  • 依赖项目数: 19
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-17