@@ -15,6 +15,7 @@ composer require phpstan/phpdoc-parser # to support raw string resolving
1515<?php
1616
1717use Symfony\Component\TypeInfo\Type;
18+ use Symfony\Component\TypeInfo\TypeIdentifier;
1819use Symfony\Component\TypeInfo\TypeResolver\TypeResolver;
1920
2021// Instantiate a new resolver
@@ -27,10 +28,21 @@ $typeResolver->resolve('bool'); // returns a "bool" Type instance
2728// Types can be instantiated thanks to static factories
2829$type = Type::list(Type::nullable(Type::bool()));
2930
30- // Type instances have several helper methods
31- $type->getBaseType(); // returns an "array" Type instance
32- $type->getCollectionKeyType(); // returns an "int" Type instance
33- $type->getCollectionValueType()->isNullable(); // returns true
31+ // Type classes have their specific methods
32+ Type::object(FooClass::class)->getClassName();
33+ Type::enum(FooEnum::class, Type::int())->getBackingType();
34+ Type::list(Type::int())->isList();
35+
36+ // Every type can be cast to string
37+ (string) Type::generic(Type::object(Collection::class), Type::int()) // returns "Collection<int >"
38+
39+ // You can check that a type (or one of its wrapped/composed parts) is identified by one of some identifiers.
40+ $type->isIdentifiedBy(Foo::class, Bar::class);
41+ $type->isIdentifiedBy(TypeIdentifier::OBJECT);
42+ $type->isIdentifiedBy('float');
43+
44+ // You can also check that a type satifies specific conditions
45+ $type->isSatisfiedBy(fn (Type $type): bool => !$type->isNullable() && $type->isIdentifiedBy(TypeIdentifier::INT));
3446```
3547
3648Resources
0 commit comments