Rewrite argtyper in Go using php-parser-in-go - #12
Merged
Conversation
TomasVotruba
force-pushed
the
go-rewrite
branch
from
September 13, 2026 10:24
abeecfa to
8c5f61c
Compare
Replace the PHP + PHPStan + Rector implementation with a self-contained Go tool built on rectorphp/php-parser-in-go. It collects the types of literal arguments passed into statically resolvable call targets (new X(), X::m(), self::m(), $this->m() and plain function calls), groups them per parameter position, and fills in missing parameter type declarations. Ambiguous types are skipped, a single type plus null becomes nullable. No type inference engine is used, so only literal values and statically resolvable targets are handled.
TomasVotruba
force-pushed
the
go-rewrite
branch
from
September 13, 2026 10:25
8c5f61c to
513b044
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces the PHP + PHPStan + Rector implementation with a self-contained Go tool built on php-parser-in-go.
What it does
argtyper add-types <path>walks the project, records the types of literal arguments passed into calls, then fills in missing parameter type declarations.int,float,string,bool,array,null, andnew X()asobject:X.new X(),X::m(),self::m(),$this->m()and plainfunction()calls.__construct), and methods that may override a parent/interface (unless private or constructor).Scope vs the old version
The PHP tool used PHPStan's type inference, so it could type a param even when the argument was a variable carrying a known type. The Go version has no inference engine - it uses only the parsed AST, so it handles literal values passed into statically resolvable targets. Calls on arbitrary variables (
$service->method(...)) are skipped, since the class cannot be resolved without inference. Classes are matched by short name.Layout
main.go- CLIinternal/finder- find PHP files in code dirsinternal/collect- record literal arg types at call sitesinternal/aggregate- resolve one type per parameterinternal/apply- add missing param types and reprintinternal/phpast- shared AST helpersCI
PHP workflows replaced with a Go build workflow (gofmt, vet, build, test). Tests cover collect, aggregate, apply and finder.