rector / argtyper
Analyze real method argument types, and add them as type declarations
Requires
- php: >=7.4
- phpstan/phpstan: ^2.0
- rector/rector: ^2.0
- dev-main
- 0.6.0
- 0.5.24
- 0.5.23
- 0.5.22
- 0.5.21
- 0.5.20
- 0.5.19
- 0.5.18
- 0.5.17
- 0.5.16
- 0.5.15
- 0.5.14
- 0.5.13
- 0.5.12
- 0.5.11
- 0.5.10
- 0.5.9
- 0.5.8
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
- 0.3.0
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.0
- 0.0.5
- 0.0.4
- 0.0.3
- 0.0.2
- 0.0.1
- dev-fix/issue-9-parameters-with-default-null-value-are-getting-the
- dev-tv-simpler-repo
- dev-fix/issue-2-implicitly-nullable-parameters-are-deprecated-are
This package is auto-updated.
Last update: 2026-06-02 21:02:44 UTC
README
There are often more known types in your project than meets the eye.
This tool detects the real types passed into method and function calls using PHPStan.
$this->hotelOverview->makeRoomAvailable(324);
Later in the code...
public function roomDetail(int $roomNumber) { $this->hotelOverview->makeRoomAvailable($roomNumber); }
Later in tests...
public function test(int $roomNumber): void { $this->hotelOverview->makeRoomAvailable($roomNumber); }
✅ Three times an int value is passed into makeRoomAvailable().
Then Rector runs and fills in the missing type declarations:
final class HotelOverview
{
- public function makeRoomAvailable($roomNumber)
+ public function makeRoomAvailable(int $roomNumber)
{
}
}
✅ An int parameter type is added to the makeRoomAvailable() method.
That’s it.
Install
composer require rector/argtyper --dev
Usage
Run it in your project directory:
vendor/bin/argtyper add-types .
Or on another project:
vendor/bin/argtyper add-types project
To see more details during the process, add the --debug option.
How It Works
At first, a set of custom PHPStan rules scans your code and records the argument types passed to method calls, static calls, new expressions, and function calls. It stores this data in temporary *.json files in the following format:
[
{
"class": "HotelOverview",
"method": "makeRoomAvailable",
"position": 0,
"type": "PHPStan\\Type\\IntegerType"
}
]
Then, custom Rector rules go through the codebase and fill in the known parameter types based on the collected data — but only where they’re missing.
With a few exceptions:
- If multiple types are found → it’s skipped.
- If union or intersection types are found → it’s skipped as ambiguous.
- If a
floatparameter type is declared but onlyintarguments are passed (e.g.30.0) → it’s skipped to avoid losing decimal precision.
Verify the Results
It’s not 100 % perfect, but in our tests it fills in about 95 % of the data correctly and saves a huge amount of manual work.
You can fix the remaining cases manually based on PHPStan or test feedback.
Happy coding!