Weave Code
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 Laravel Package

sebastian/type

sebastian/type provides lightweight value objects for representing and working with PHP’s type system (built-in, class, union, intersection, nullable, etc.). Useful for static analysis tools, reflection helpers, and test utilities that need precise type modeling.

View on GitHub
Deep Wiki
Context7

Collection of value objects that represent the types of the PHP type system

Frequently asked questions about Type
How can I use sebastian/type for Laravel validation logic?
sebastian/type lets you model complex types (unions, intersections, nullable) as objects, which you can then use to validate FormRequest payloads or API inputs. For example, create a UnionType for `int|string` and enforce it in custom validation rules. It integrates seamlessly with Laravel’s validation pipeline for type-safe payloads.
Does sebastian/type work with PHPStan or Psalm in Laravel?
Yes, it’s designed for static analysis tools. Use ReflectionMapper to convert PHPStan/Psalm’s type representations into sebastian/type objects, enabling custom rules. For example, enforce return type consistency in services or validate Eloquent model properties. Check phpstan.php for conflicts after upgrading.
What’s the difference between sebastian/type and php-types for Laravel?
sebastian/type focuses on **static type modeling** (e.g., for analyzers, reflection helpers, or test infrastructure), while php-types is runtime-focused (e.g., validating variables at execution). Use sebastian/type for tooling and php-types for runtime checks. They complement each other in Laravel’s type ecosystem.
How do I handle class aliases (e.g., DateTimeImmutable as DateTime) in sebastian/type?
The v7.0.1 fix improves alias resolution, but custom aliases may still need explicit handling. Use ReflectionMapper::fromType() with aliased classes and verify assignability with Type::isAssignableFrom(). For Laravel, test DateTimeImmutable ↔ DateTime bindings in your container or validation logic.
Can I use sebastian/type for OpenAPI or API contract generation in Laravel?
Absolutely. ReflectionMapper converts PHP types (e.g., method return types) into sebastian/type objects, which you can then serialize into OpenAPI schemas. For example, map an Eloquent model’s properties to OpenAPI types using ReflectionMapper::fromPropertyType(). Works well with packages like darkaonline/l5-swagger.
What’s the PHP version requirement for sebastian/type in Laravel?
v7.0.0+ requires PHP 8.4+, while v6.0+ supports PHP 8.3 (Laravel 10’s minimum). Pin to ^6.0 if stuck on PHP 8.3, but note you’ll miss future fixes. Check your Laravel version’s PHP requirements before upgrading.
How do I test sebastian/type in a Laravel project?
Add it as a dev dependency (`composer require --dev sebastian/type`) and test core functionality like ReflectionMapper::fromType() with class aliases. Use Type::isAssignableFrom() to assert type compatibility in unit tests (e.g., mock objects or service return types). Works alongside PestPHP or PHPUnit.
Will sebastian/type break existing PHPStan/Psalm rules in Laravel?
Unlikely, but audit your phpstan.php or psalm.xml for custom rules post-upgrade. The package normalizes types, which may require adjustments to existing rules. For example, union types (e.g., `int|string`) might need reconfiguration. Test with `--level=8` in CI/CD.
Can I extend sebastian/type for custom domain types (e.g., Money, UserId)?
Yes, sebastian/type is composable. Extend the base Type class or create custom value objects (e.g., MoneyType) by implementing the Type interface. Useful for business logic types in Laravel’s validation or DTO layers. Document your custom types for IDE support.
How does sebastian/type improve Laravel’s dependency injection (DI) type safety?
It provides precise type modeling for DI containers, especially with class aliases (e.g., DateTimeImmutable vs. DateTime). Use ReflectionMapper to validate bindings and enforce type consistency in service providers. For example, ensure a `UserRepository` always returns `User` objects, not subclasses.
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata