https://github.com/symfony/type-info
Extracts PHP types information.
https://github.com/symfony/type-info
component php phpdoc phpstan symfony symfony-component type
Last synced: about 1 month ago
JSON representation
Extracts PHP types information.
- Host: GitHub
- URL: https://github.com/symfony/type-info
- Owner: symfony
- License: mit
- Created: 2024-02-04T09:44:18.000Z (over 1 year ago)
- Default Branch: 7.2
- Last Pushed: 2025-05-02T09:22:05.000Z (about 2 months ago)
- Last Synced: 2025-05-05T06:44:20.035Z (about 2 months ago)
- Topics: component, php, phpdoc, phpstan, symfony, symfony-component, type
- Language: PHP
- Homepage: https://symfony.com/type-info
- Size: 259 KB
- Stars: 150
- Watchers: 5
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
TypeInfo Component
==================The TypeInfo component extracts PHP types information.
Getting Started
---------------```bash
composer require symfony/type-info
composer require phpstan/phpdoc-parser # to support raw string resolving
``````php
resolve(new \ReflectionProperty(Dummy::class, 'id')); // returns an "int" Type instance
$typeResolver->resolve('bool'); // returns a "bool" Type instance// Types can be instantiated thanks to static factories
$type = Type::list(Type::nullable(Type::bool()));// Type classes have their specific methods
Type::object(FooClass::class)->getClassName();
Type::enum(FooEnum::class, Type::int())->getBackingType();
Type::list(Type::int())->isList();// Every type can be cast to string
(string) Type::generic(Type::object(Collection::class), Type::int()) // returns "Collection"// You can check that a type (or one of its wrapped/composed parts) is identified by one of some identifiers.
$type->isIdentifiedBy(Foo::class, Bar::class);
$type->isIdentifiedBy(TypeIdentifier::OBJECT);
$type->isIdentifiedBy('float');// You can also check that a type satifies specific conditions
$type->isSatisfiedBy(fn (Type $type): bool => !$type->isNullable() && $type->isIdentifiedBy(TypeIdentifier::INT));
```Resources
---------
* [Documentation](https://symfony.com/doc/current/components/type_info.html)
* [Contributing](https://symfony.com/doc/current/contributing/index.html)
* [Report issues](https://github.com/symfony/symfony/issues) and
[send Pull Requests](https://github.com/symfony/symfony/pulls)
in the [main Symfony repository](https://github.com/symfony/symfony)