Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Type Resolver Laravel Package

phpdocumentor/type-resolver

Resolves PHP DocBlock types and partial class names into fully qualified names, and resolves structural element references into FQSENs, per PSR-5. Useful for static analysis, documentation generators, and reflection tooling.

View on GitHub
Deep Wiki
Context7

Getting Started

Install or upgrade with Composer:

composer require phpdocumentor/type-resolver:^2.1

Start by resolving simple types:

use phpDocumentor\Reflection\TypeResolver;

$resolver = new TypeResolver();
$type = $resolver->resolve('string|int');

For real-world use, pair with Context to resolve partial class names (e.g., @var UserService → \App\Services\UserService). Use ContextFactory::createForNamespace() to auto-generate context from source code and namespace. Version 2.1.0 is a minor release with no breaking changes; composer update from 2.0.x is safe.

Implementation Patterns

  • DocBlock parsing: Use alongside phpreflection (e.g., ReflectionMethod) to extract types from docblocks:
    $context = $contextFactory->createFromReflector(new ReflectionMethod(...));
    $type = $resolver->resolve('@return User[]', $context);
    
  • Code generation & static analysis: Feed resolved types into AST tools (e.g., PHPStan, Psalm integrations), or generate type-aware documentation.
  • FQSEN resolution: Resolve @see references:
    $fqsen = (new FqsenResolver())->resolve('App\Controller::index()', $context);
    // Yields \App\Controller::index()
    
  • Generic and pseudo-types (v2+, expanded in 2.1.0): Use for modern PHPDoc type hints like list<string>, array<int, User>, non-empty-array, class-string<MyClass>, and the newly supported non-decimal-int-string pseudo-type.
  • IDE/tooling integrations: Write custom linters, refactoring tools, or autocompletion helpers that understand PHPDoc semantics.

Gotchas and Tips

  • Context is critical for resolving partial class names. Skipping it → @var Repository stays unresolved. Always derive context from actual file scope, not just the namespace.
  • Pseudo-types like self, static, parent are handled—but only in a valid Context with the correct FQCN.
  • Nullable types (?string) are auto-wrapped in Nullable—check with $type instanceof Nullable and unwrap via $type->getInnerType().
  • v2 breaking changes: GenericTemplate removed, Collection → GenericType, removed True_/False_ aliases. See upgrade guide.
  • non-decimal-int-string requires 2.1.0+: If you're on 2.0.x, upgrade before relying on it. Treat it as a PHPDoc/pseudo-type constraint for tooling, not runtime validation.
  • Memory/perf: Creating Context via ContextFactory::createForNamespace() parses full source—cache results when processing many docblocks (e.g., across an entire codebase).
  • Validation tip: Always check $type->getValue() or cast to string ((string)$type) to get normalized output—ideal for logging or codegen.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console