{"id":33964140,"url":"https://github.com/rectorphp/argtyper","last_synced_at":"2025-12-12T22:57:39.846Z","repository":{"id":325427442,"uuid":"683683272","full_name":"rectorphp/argtyper","owner":"rectorphp","description":"[WIP] Analyze real method argument types, and add them as type declarations","archived":false,"fork":false,"pushed_at":"2025-11-24T15:55:01.000Z","size":10591,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-30T02:10:11.439Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rectorphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-08-27T11:23:22.000Z","updated_at":"2025-11-24T15:39:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rectorphp/argtyper","commit_stats":null,"previous_names":["rectorphp/argtyper"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/rectorphp/argtyper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Fargtyper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Fargtyper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Fargtyper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Fargtyper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rectorphp","download_url":"https://codeload.github.com/rectorphp/argtyper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rectorphp%2Fargtyper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27694331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-12-12T22:57:39.035Z","updated_at":"2025-12-12T22:57:39.838Z","avatar_url":"https://github.com/rectorphp.png","language":"PHP","readme":"# Fill Parameter Types based on Passed Values\n\nThere are often more known types in your project than meets the eye.  \nThis tool detects the **real** types passed into method and function calls using PHPStan.\n\n\u003cbr\u003e\n\n```php\n$this-\u003ehotelOverview-\u003emakeRoomAvailable(324);\n```\n\n\u003cbr\u003e\n\nLater in the code...\n\n```php\npublic function roomDetail(int $roomNumber)\n{\n    $this-\u003ehotelOverview-\u003emakeRoomAvailable($roomNumber);\n}\n```\n\n\u003cbr\u003e\n\nLater in tests...\n\n```php\npublic function test(int $roomNumber): void\n{\n    $this-\u003ehotelOverview-\u003emakeRoomAvailable($roomNumber);\n}\n```\n\n✅ Three times an `int` value is passed into `makeRoomAvailable()`.\n\n\u003cbr\u003e\n\nThen [Rector](https://getrector.com) runs and fills in the missing type declarations:\n\n```diff\n final class HotelOverview\n {\n-    public function makeRoomAvailable($roomNumber)\n+    public function makeRoomAvailable(int $roomNumber)\n     {\n     }\n }\n```\n\n✅ An `int` parameter type is added to the `makeRoomAvailable()` method.\n\n\u003cbr\u003e\n\nThat’s it.\n\n\u003cbr\u003e\n\n## Install\n\n```bash\ncomposer require rector/argtyper --dev\n```\n\n\u003cbr\u003e\n\n## Usage\n\nRun it in your project directory:\n\n```bash\nvendor/bin/argtyper add-types .\n```\n\n\u003cbr\u003e\n\nOr on another project:\n\n```bash\nvendor/bin/argtyper add-types project\n```\n\nTo see more details during the process, add the `--debug` option.\n\n\u003cbr\u003e\n\n## How It Works\n\nAt 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:\n\n```json\n[\n    {\n        \"class\": \"HotelOverview\",\n        \"method\": \"makeRoomAvailable\",\n        \"position\": 0,\n        \"type\": \"PHPStan\\\\Type\\\\IntegerType\"\n    }\n]\n```\n\n\u003cbr\u003e\n\nThen, 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.\n\nWith a few exceptions:\n\n* If multiple types are found → it’s skipped.\n* If union or intersection types are found → it’s skipped as ambiguous.\n* If a `float` parameter type is declared but only `int` arguments are passed (e.g. `30.0`) → it’s skipped to avoid losing decimal precision.\n\n\u003cbr\u003e\n\n## Verify the Results\n\nIt’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.  \nYou can fix the remaining cases manually based on PHPStan or test feedback.\n\n\u003cbr\u003e\n\nHappy coding!\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frectorphp%2Fargtyper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frectorphp%2Fargtyper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frectorphp%2Fargtyper/lists"}