- How do I install phpdocumentor/type-resolver with Composer?
- Run composer require phpdocumentor/type-resolver and pin the constraint to ^2.1 so you are guaranteed the latest pseudo-type coverage. There is no Laravel auto-discovery, service provider or config file to publish because this is a plain library. In practice you will also add phpdocumentor/reflection-docblock so you can extract DocBlocks before resolving the types inside them.
- Does phpdocumentor/type-resolver support PHP 8.3, 8.4 and Laravel 10, 11 and 12?
- Yes. The package is framework-agnostic and declares no Illuminate requirements, so it does not conflict with Laravel's dependency graph on recent versions. It supports PHP 7.4+ and PHP 8.x including 8.3 and 8.4. Because nothing in the package tracks Laravel's release cycle, there is no Laravel major-version upgrade risk, and the only real breaking path is the v1 to v2 migration.
- Do I need a service provider or facade to use TypeResolver in Laravel?
- No. The package ships no service provider, config file or facade; TypeResolver and FqsenResolver are plain classes you instantiate yourself. In a Laravel app the clean approach is to bind them in your own small TypeResolverServiceProvider and expose them through a thin adapter. That keeps your domain layer free of framework coupling and makes the resolvers easy to mock in tests.
- How do I resolve a partial class name in a DocBlock to a fully qualified class name?
- Build a Context that represents the file's namespace and use statements, then pass the DocBlock type string and that Context to the resolver. Partial class names are expanded to FQCNs using the Context you supplied, and the result is returned as immutable value objects you can serialize or cache. Because the Context drives resolution, construct it per file or per namespace scope instead of trying to reuse one globally.
- What is the difference between TypeResolver and FqsenResolver?
- TypeResolver parses DocBlock type expressions, including primitives, arrays and compound types, and resolves partial class names to FQCNs. FqsenResolver resolves structural element references such as methods, properties, class constants, functions and global constants into fully qualified structural element names. Most documentation generators and static analysis tools use both together.
- What happens when a DocBlock type cannot be resolved, does it throw an exception?
- Handling unresolvable types gracefully is the main integration detail and belongs in your adapter layer. Wrap resolution in a try/catch and also inspect the returned value object, because the resolver may hand back an unresolved or generic object type rather than the concrete class you expected. Before relying on the output in CI, add tests against the docblock shapes in your own codebase, especially vendor-prefixed FQSENs.
- Is phpdocumentor/type-resolver safe to use under Laravel Octane and in queue workers?
- The resolvers are stateless, so they are safe to run under Octane and inside queue workers. The bigger point is that this is build-time and CLI-time tooling rather than a runtime request-path dependency, so there is little reason to call it on every request. If you cache resolved types, keep that cache in your own layer rather than inside the resolver objects.
- Does version 2.1.0 support non-decimal-int-string and other pseudo-types in union positions?
- Version 2.1.0 adds support for the non-decimal-int-string pseudo-type, covering hex, octal and binary integer string literals, through PR #308. That change is purely additive with no signature changes, so you can pin ^2.1 immediately. Whether it discriminates non-decimal-int-string from ordinary string inside union and generic positions should be asserted with your own test cases.
- How does it perform across a 10k+ file monorepo, and can I cache the results?
- The resolvers are lightweight with a minimal dependency footprint, but repeatedly resolving every docblock across 10k+ files is where CPU and memory cost accumulates. Because the resolvers are stateless, caching is your responsibility: cache parse results keyed by file, namespace Context and type string so you never re-resolve the same FQSENs during a scan. A warm cache is what makes it viable in CI.
- What are the alternatives to phpdocumentor/type-resolver for parsing PHPDoc types?
- phpstan/phpdoc-parser is the common alternative and is a sensible choice if you already live inside the PHPStan ecosystem. The main argument for phpdocumentor/type-resolver is its tight pairing with phpdocumentor/reflection-docblock plus a small, stable, framework-agnostic API. Whichever you pick, wrap it behind an adapter so you can swap parsers later without touching your domain code.