PHPackages                             simensen/rector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. simensen/rector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

simensen/rector
===============

Simensen's Rules and Tools for Rector

v0.1.0(4w ago)01.5kMITPHP

Since Jul 13Pushed 4w ago1 watchersCompare

[ Source](https://github.com/simensen/simensen-rector)[ Packagist](https://packagist.org/packages/simensen/rector)[ RSS](/packages/simensen-rector/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (3)Used By (0)

Simensen Rector Rules
=====================

[](#simensen-rector-rules)

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

Simensen's custom rules and tools for [Rector](https://github.com/rectorphp/rector) - a PHP automated refactoring tool.

Installation
------------

[](#installation)

Install via Composer:

```
composer require simensen/rector
```

Rules
-----

[](#rules)

### RemoveDefaultFromImplicitlyRequiredParamRector

[](#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 had `null` 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
-----

[](#usage)

Add the rector to your `rector.php` configuration:

```
