diff --git a/src/Symfony/Component/TypeInfo/README.md b/src/Symfony/Component/TypeInfo/README.md index b654e271a1c6b..d9b3a2e5bbf2f 100644 --- a/src/Symfony/Component/TypeInfo/README.md +++ b/src/Symfony/Component/TypeInfo/README.md @@ -15,6 +15,7 @@ composer require phpstan/phpdoc-parser # to support raw string resolving resolve('bool'); // returns a "bool" Type instance // Types can be instantiated thanks to static factories $type = Type::list(Type::nullable(Type::bool())); -// Type instances have several helper methods -$type->getBaseType(); // returns an "array" Type instance -$type->getCollectionKeyType(); // returns an "int" Type instance -$type->getCollectionValueType()->isNullable(); // returns true +// 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