valksor/php-dev-cs-fixer-custom-fixers
Composer 安装命令:
composer require valksor/php-dev-cs-fixer-custom-fixers
包简介
Custom PHP-CS-Fixer rules for automated code style enforcement including Doctrine migration files and project-specific standards
关键字:
README 文档
README
A comprehensive PHP library providing custom fixers for PHP-CS-Fixer to enhance code quality, enforce modern coding standards, and improve development workflow efficiency.
Use Cases
Code Quality Enhancement
- Modern PHP Standards: Enforce PHP 8.4+ best practices including promoted constructor properties
- Readability Improvements: Automatic formatting for better code readability and maintainability
- Team Consistency: Ensure consistent coding style across development teams
- Migration Cleanup: Automatically clean up auto-generated comments in Doctrine migration files
Development Workflow Automation
- Automated Refactoring: Convert traditional constructor patterns to modern promoted properties
- Code Cleanup: Remove unnecessary function calls and redundant code patterns
- Standards Enforcement: Go beyond PSR-12 with project-specific coding standards
- CI/CD Integration: Seamless integration with continuous integration pipelines
Performance Optimization
- Code Optimization: Remove inefficient patterns like unnecessary
strlen()calls in comparisons - Clean Code: Eliminate redundant
dirname()calls and other unnecessary constructs - Modern Patterns: Promote use of modern PHP features for better performance
Installation
Install the package via Composer:
composer require valksor/php-dev-cs-fixer-custom-fixers --dev
Requirements
- PHP 8.4 or higher
- friendsofphp/php-cs-fixer (3.81.0 or higher)
- symfony/finder (7.0 or higher)
- valksor/php-functions-preg (^1.0)
Optional Dependencies
- doctrine/migrations: For fixing migration file comments (suggested)
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 ValksorDev\PhpCsFixerCustomFixers\Fixers; $finder = Finder::create() ->in(__DIR__) ->exclude('vendor') ->name('*.php'); $config = new Config(); $config ->setRules([ '@PSR12' => true, // Enable all Valksor custom fixers 'ValksorPhpCsFixerCustomFixers/declare_after_opening_tag' => true, 'ValksorPhpCsFixerCustomFixers/doctrine_migrations' => true, 'ValksorPhpCsFixerCustomFixers/line_break_between_method_arguments' => true, 'ValksorPhpCsFixerCustomFixers/line_break_between_statements' => true, 'ValksorPhpCsFixerCustomFixers/no_useless_dirname_call' => true, 'ValksorPhpCsFixerCustomFixers/no_useless_strlen' => true, 'ValksorPhpCsFixerCustomFixers/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 ValksorDev\PhpCsFixerCustomFixers\Fixer\DoctrineMigrationsFixer; $finder = Finder::create() ->in(__DIR__) ->exclude('vendor') ->name('*.php'); $config = new Config(); $config ->setRules([ '@PSR12' => true, // Enable only specific Valksor custom fixers 'ValksorPhpCsFixerCustomFixers/doctrine_migrations' => true, ]) ->setFinder($finder) ->registerCustomFixers([ new DoctrineMigrationsFixer(), ]); 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) { } }
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+).
Contributing
- Code style requirements (PSR-12)
- Testing requirements for PRs
- One feature per pull request
- Development setup instructions
To contribute to the custom fixers:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-fixer) - Implement your custom fixer following the existing patterns
- Add comprehensive tests for your fixer
- Ensure all tests pass and code style is correct
- Submit a pull request
Creating a New Custom Fixer
When adding a new custom fixer:
-
Extend the appropriate base class:
use ValksorDev\PhpCsFixerCustomFixers\PhpCsFixer\AbstractFixer; class YourCustomFixer extends AbstractFixer { // Implement required methods }
-
Add comprehensive test coverage in
tests/Fixer/YourCustomFixerTest.php -
Register the fixer in
src/ValksorDev/PhpCsFixerCustomFixers/Fixers.php -
Update documentation with examples
Security
If you discover any security-related issues, please email us at packages@valksor.com instead of using the issue tracker.
Support
- Documentation: Full documentation
- Issues: GitHub Issues for bug reports and feature requests
- Discussions: GitHub Discussions for questions and community support
Credits
- Original Author - Creator and maintainer
- All Contributors - Thank you to all who contributed
- PHP-CS-Fixer Project - Core framework and inspiration
- Valksor Project - Part of the larger Valksor PHP ecosystem
License
This package is licensed under the BSD-3-Clause License.
About Valksor
This package is part of the valksor/php-dev 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
- Symfony bundle for easy configuration
- And much more
If you find these custom fixers useful, you might want to check out the full Valksor project for additional tools and utilities that can enhance your Symfony application development.
To install the complete package:
composer require valksor/php-dev
valksor/php-dev-cs-fixer-custom-fixers 适用场景与选型建议
valksor/php-dev-cs-fixer-custom-fixers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「tools」 「automation」 「static-analysis」 「php-cs-fixer」 「code-style」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 valksor/php-dev-cs-fixer-custom-fixers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 valksor/php-dev-cs-fixer-custom-fixers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 valksor/php-dev-cs-fixer-custom-fixers 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
A Laravel package to retrieve data from Google Search Console
Command-line utility for Vtiger CRM.
Historical accounting for contacts
GHT D-Tools Bundle
Allow KoolReport to use twig template engine to render view
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2025-10-27