simensen / rector
Simensen's Rules and Tools for Rector
Installs: 1 546
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- phpstan/phpstan: ^1.11
- rector/rector: ^1.2
Requires (Dev)
- ergebnis/composer-normalize: ^2.43
This package is auto-updated.
Last update: 2025-07-13 03:05:23 UTC
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 (
?type
or|null
) to parameters that hadnull
as 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