Skip to content

Commit 4b55acb

Browse files
committed
minor symfony#59149 [TypeInfo] Fix outdated README (mtarld)
This PR was merged into the 7.2 branch. Discussion ---------- [TypeInfo] Fix outdated README | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Fix TypeInfo's `README.md` by updating usage examples Commits ------- 34d30c7 [TypeInfo] Fix outdated README
2 parents 49f1326 + 34d30c7 commit 4b55acb

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Symfony/Component/TypeInfo/README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ composer require phpstan/phpdoc-parser # to support raw string resolving
1515
<?php
1616

1717
use Symfony\Component\TypeInfo\Type;
18+
use Symfony\Component\TypeInfo\TypeIdentifier;
1819
use 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

3648
Resources

0 commit comments

Comments
 (0)