simensen/rector
最新稳定版本:v0.0.1
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
统计信息
- 总下载量: 1.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-28