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.
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- Align multiline function params (or remove alignment).ErickSkrauch/blank_line_around_class_body- Add space inside class body.ErickSkrauch/blank_line_before_return- Add blank line beforereturn.ErickSkrauch/line_break_after_statements- Add blank line after control structures.ErickSkrauch/multiline_if_statement_braces- Fix brace position for multilineifstatements.ErickSkrauch/ordered_overrides- Sort overridden methods.ErickSkrauch/remove_class_name_method_usages- Replace::className()with:class(Yii2).
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 totrue, forces variables alignment. Onfalseforces strictly no alignment. You can set it tonullto disable touching of variables. Default:true. -
defaults- when set totrue, forces defaults alignment. Onfalseforces strictly no alignment. You can set it tonullto 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 tofalse, 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 tofalse, 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
extendsand appliesimplementsafterwards. 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_interfacesfixer, 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 erickskrauch/php-cs-fixer-custom-fixers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
A Symfony bundle for using the CssToInlineStyles translator by tijsverkoyen
Monolog bridge for PHP Debugbar
Fixing php code style
The coding standard applying to all Youdot PHP projects, based on Doctrine set of PHPCS rules, with additional checks.
Simple and fast methods to read private properties and call private methods
统计信息
- 总下载量: 2.37M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 30
- 点击次数: 17
- 依赖项目数: 19
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-17