vairogs/php-cs-fixer-custom-fixers
Composer 安装命令:
composer require vairogs/php-cs-fixer-custom-fixers
包简介
README 文档
README
A PHP library providing custom fixers for PHP-CS-Fixer to enhance code quality and enforce coding standards.
Installation
Install the package via Composer:
composer require vairogs/php-cs-fixer-custom-fixers
Requirements
PHP 8.4 or higher
Usage
The package provides custom fixers that can be used with PHP-CS-Fixer to automatically fix code style issues.
Basic Usage
use PhpCsFixer\Config; use PhpCsFixer\Finder; use Vairogs\PhpCsFixerCustomFixers\Fixers; $finder = Finder::create() ->in(__DIR__) ->exclude('vendor') ->name('*.php'); $config = new Config(); $config ->setRules([ '@PSR12' => true, // Enable all Vairogs custom fixers 'VairogsPhpCsFixerCustomFixers/declare_after_opening_tag' => true, 'VairogsPhpCsFixerCustomFixers/doctrine_migrations' => true, 'VairogsPhpCsFixerCustomFixers/isset_to_array_key_exists' => true, 'VairogsPhpCsFixerCustomFixers/line_break_between_method_arguments' => true, 'VairogsPhpCsFixerCustomFixers/line_break_between_statements' => true, 'VairogsPhpCsFixerCustomFixers/no_useless_dirname_call' => true, 'VairogsPhpCsFixerCustomFixers/no_useless_strlen' => true, 'VairogsPhpCsFixerCustomFixers/promoted_constructor_property' => true, ]) ->setFinder($finder); // Register custom fixers $fixers = new Fixers(); foreach ($fixers as $fixer) { $config->registerCustomFixers([$fixer]); } return $config;
Registering Specific Fixers
If you only want to use specific fixers, you can register them individually:
use PhpCsFixer\Config; use PhpCsFixer\Finder; use Vairogs\PhpCsFixerCustomFixers\Fixer\DoctrineMigrationsFixer; use Vairogs\PhpCsFixerCustomFixers\Fixer\IssetToArrayKeyExistsFixer; $finder = Finder::create() ->in(__DIR__) ->exclude('vendor') ->name('*.php'); $config = new Config(); $config ->setRules([ '@PSR12' => true, // Enable only specific Vairogs custom fixers 'VairogsPhpCsFixerCustomFixers/doctrine_migrations' => true, 'VairogsPhpCsFixerCustomFixers/isset_to_array_key_exists' => true, ]) ->setFinder($finder) ->registerCustomFixers([ new DoctrineMigrationsFixer(), new IssetToArrayKeyExistsFixer(), ]); return $config;
Available Fixers
DeclareAfterOpeningTagFixer
Ensures that declare(strict_types = 1) is placed immediately after the opening PHP tag.
DoctrineMigrationsFixer
Removes unnecessary auto-generated comments from Doctrine migration files.
// Before /** * Auto-generated Migration: Please modify to your needs! */ final class Version20230101000000 extends AbstractMigration { public function up(Schema $schema) { // this up() migration is auto-generated, please modify it to your needs } } // After final class Version20230101000000 extends AbstractMigration { public function up(Schema $schema) { } }
IssetToArrayKeyExistsFixer
Replaces isset($array[$key]) with array_key_exists($key, $array) when possible.
// Before if (isset($array[$key])) { echo $array[$key]; } // After if (array_key_exists($key, $array)) { echo $array[$key]; }
Note: This fixer is marked as risky because isset() and array_key_exists() have slightly different behaviors. isset() also checks if the value is not null, while array_key_exists() only checks if the key exists.
LineBreakBetweenMethodArgumentsFixer
Ensures that method arguments are separated by line breaks when there are multiple arguments.
LineBreakBetweenStatementsFixer
Ensures that statements are separated by line breaks for better readability.
NoUselessDirnameCallFixer
Removes unnecessary dirname() calls.
NoUselessStrlenFixer
Removes unnecessary strlen() calls when used in comparisons.
PromotedConstructorPropertyFixer
Converts traditional constructor property assignments to promoted properties (PHP 8.0+).
License
This package is licensed under the BSD-3-Clause License.
About Vairogs
This package is part of the vairogs/vairogs project - a comprehensive PHP library and Symfony bundle that provides a collection of utilities, components, and integrations for Symfony applications.
The main project includes:
- Various utility functions and components
- Doctrine ORM tools and extensions
- API Platform integrations
- Symfony bundle for easy configuration
- And much more
If you find these custom fixers useful, you might want to check out the full Vairogs project for additional tools and utilities that can enhance your Symfony application development.
To install the complete package:
composer require vairogs/vairogs
vairogs/php-cs-fixer-custom-fixers 适用场景与选型建议
vairogs/php-cs-fixer-custom-fixers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 37 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 08 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 vairogs/php-cs-fixer-custom-fixers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vairogs/php-cs-fixer-custom-fixers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 37
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2024-08-20