simensen/rector
Composer 安装命令:
composer require simensen/rector
包简介
Simensen's Rules and Tools for Rector
README 文档
README
Simensen's custom rules and tools for Rector - a PHP automated refactoring tool.
Installation
Install via Composer:
composer require simensen/rector
Rules
RemoveDefaultFromImplicitlyRequiredParamRector
This rector removes default values from function/method parameters when they are followed by required parameters, making the code more explicit and preventing potential runtime errors.
What it does:
- Removes default values from parameters that are implicitly required (have required parameters after them)
- Adds nullable types (
?typeor|null) to parameters that hadnullas their default value - Preserves default values only for trailing optional parameters
Example transformation:
// Before class Example { public function __construct(string $a = null, string $b) { } } // After class Example { public function __construct(?string $a, string $b) { } }
More complex example:
// Before public function method( string $a = 'default', string $b, string $c = null, string $d, string $e = 'end' ) // After public function method( string $a, string $b, ?string $c, string $d, string $e = 'end' )
Usage
Add the rector to your rector.php configuration:
<?php declare(strict_types=1); use Rector\Config\RectorConfig; use Simensen\Rector\Rules\Params\Rector\RemoveDefaultFromImplicitlyRequiredParamRector; return RectorConfig::configure() ->withRules([ RemoveDefaultFromImplicitlyRequiredParamRector::class, ]);
Then run Rector:
vendor/bin/rector process src/
Development
Requirements
- PHP 8.1+
- Composer
Setup
# Install dependencies make vendor # Install development tools make tools
Testing
# Run tests make test # Run code style checks and fixes make cs
Available Make Targets
make it- Default target, installs tools and dependenciesmake vendor- Install Composer dependenciesmake tools- Install development tools via PHIVEmake test- Run PHPUnit testsmake cs- Run code style checks and fixesmake clean- Remove vendor and tools directoriesmake realclean- Clean and also remove composer.lockmake help- Display available targets
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for any new functionality
- Ensure all tests pass:
make test - Ensure code style is correct:
make cs - Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
Beau Simensen - GitHub
simensen/rector 适用场景与选型建议
simensen/rector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.55k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 simensen/rector 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 simensen/rector 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 1.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-28