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 Info Extras Laravel Package

radebatz/type-info-extras

Type Info Extras extends the radebatz/type-info package with additional type classes and utilities for working with complex PHP types. It helps inspect unions, intersections, generics, and docblock types, making it useful for static analysis, reflection, and code generation tools.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package alongside symfony/type-info (v7.3.8+ or v7.4.1+ or v8.0+). It’s designed as a drop-in extension — no complex setup required. Once installed, the extras are automatically registered via Symfony’s autowiring or manual service registration if needed. The first practical use is extending type resolution for advanced PHPDoc annotations (e.g., @phpstan-type, @psalm-type, or custom shape-like structures) that symfony/type-info alone cannot fully parse. Check the README (if available) or inspect the src/ folder for supported types — especially ObjectShapeType and improved array resolution in v1.0.6+.

Implementation Patterns

  • Enhanced Property Type Resolution: Use the TypeInfo extension to accurately resolve types from complex PHPDoc, such as @return array{foo: string, bar: int} or union types with generic-like shapes. Ideal for automated DTO/VO validation, API schemas, or ORM-like metadata extraction.
  • Conditional Shape Types: Where symfony/type-info falls back to mixed for @phpstan-type-defined shapes, this package adds support for ObjectShapeType, enabling more precise reflection — useful in static analysis tooling or schema generation.
  • Type-Aware Formatters & Serializers: Wrap your type resolver with the extras’ extensions to produce accurate type metadata for GraphQL, OpenAPI, or DTO hydration layers.
  • Testing & Mocking: When writing tests for type-sensitive services, use the extras to assert against resolved Type instances beyond basic scalars or class names. From v1.0.10+, add explicit test cases for self-referential @phpstan-type / @psalm-type aliases and assert that resolution throws a clear exception rather than looping forever — this guards against regressions in your own type graphs.

Gotchas and Tips

  • Strict PHP Version Dependency: Requires PHP ≥8.2 — ensure your dev/test environments match. Failure here leads to cryptic TypeError or autoloading issues.
  • No Standalone Usage: This is not a replacement for symfony/type-info — it extends it. You must still instantiate/autowire the base TypeResolver and augment it with the extras.
  • Recursive Aliases Now Throw (v1.0.10+): Self-referential extra type aliases (e.g. a @phpstan-type that references itself directly or indirectly) now raise an exception instead of recursing until PHP’s memory/stack limit is hit. Catch and surface this as a domain-friendly validation error when resolving untrusted PHP source, and treat it as a signal that your alias taxonomy needs a base case.
  • Version Pinning on Dependencies: With support for multiple symfony/type-info branches (^7.3.8, ^7.4.1, ^8.0, ^8.1-@dev), use Composer’s version constraints carefully — mixing incompatible symfony/* versions may cause runtime type errors or missing classes. Check composer.json’s require section before upgrading — v1.0.10 tidies the tooling config and explicitly states the supported type-info compatibility, so re-read it after each bump.
  • Empty Composer suggests/conflicts: The package doesn’t declare conflicts or optional integrations — test in isolation if using alongside phpstan/extension-installer or phpstan/phpdoc-parser v1.x (unsupported).
  • Debug Tip: Enable Xdebug or var_dump($type->toString()) to inspect resolved ObjectShapeType members — the internal shape keys may differ from PHPDoc string representation, especially with @phpstan-type aliases. If resolution terminates with an exception in v1.0.10+, inspect the alias chain in the stack trace to locate the cycle.
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.
dakiquang/laravel-oauth-refresh-lock
woda/laravel-worktrees
dalefranks/ramasite
faghy/laracashbook
roundly-consulting/google-places-for-laravel
roundly-consulting/kubernetes-api-for-laravel
roundly-consulting/plausible-for-laravel
gvp/gvp-laravel-template
metasyncsite/laravel-metasync-client
roundly-consulting/onboarding-for-laravel
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
adachsoft/changelog-linter