@@ -43,9 +43,9 @@ to the :class:`Symfony\\Component\\TypeInfo\\Type` static methods as following::
4343Resolvers
4444~~~~~~~~~ 
4545
46- The second way of using  the component is to use  ``TypeInfo `` to resolve a type
47- based on reflection or a simple string, this  is aimed towards  libraries that wants to 
48- describe a class or anything that has  a type easily ::
46+ The second way to use  the component is by using  ``TypeInfo `` to resolve a type
47+ based on reflection or a simple string. This approach  is designed for  libraries
48+ that need a simple way to  describe a class or anything with  a type::
4949
5050    use Symfony\Component\TypeInfo\Type; 
5151    use Symfony\Component\TypeInfo\TypeResolver\TypeResolver; 
@@ -82,13 +82,15 @@ Each of these calls will return you a ``Type`` instance that corresponds to the
8282static method used. You can also resolve types from a string (as shown in the
8383``bool `` parameter of the previous example)
8484
85- PHPDoc parsing 
85+ PHPDoc Parsing 
8686~~~~~~~~~~~~~~ 
8787
88- But most times you won't have clean typed properties or you want a more precise type
89- thank to advanced PHPDoc, to do that you would want a string resolver based on that PHPDoc.
90- First you will require ``phpstan/phpdoc-parser `` package from composer to support string
91- revolving. Then you would do as following::
88+ In many cases, you may not have cleanly typed properties or may need more precise
89+ type definitions provided by advanced PHPDoc. To achieve this, you can use a string
90+ resolver based on the PHPDoc annotations.
91+ 
92+ First, run the command ``composer require phpstan/phpdoc-parser `` to install the
93+ PHP package required for string resolving. Then, follow these steps::
9294
9395    use Symfony\Component\TypeInfo\TypeResolver\TypeResolver; 
9496
@@ -106,35 +108,40 @@ revolving. Then you would do as following::
106108    $typeResolver->resolve(new \ReflectionProperty(Dummy::class, 'id')); // returns an "int" Type 
107109    $typeResolver->resolve(new \ReflectionProperty(Dummy::class, 'id')); // returns a collection with "int" as key and "string" as values Type 
108110
109- Advanced usages 
111+ Advanced Usages 
110112~~~~~~~~~~~~~~~ 
111113
112- There is many methods to manipulate and check types depending on your needs within the TypeInfo components.
114+ The TypeInfo component provides various methods to manipulate and check types,
115+ depending on your needs.
113116
114- If you need a check a  simple Type ::
117+ Checking a ** simple type  ** ::
115118
116-     // You need to check if a Type  
117-     $type = Type::int(); // with a simple int type  
118-     // You can  check if a given  type comply with a given  identifier 
119-     $type->isIdentifiedBy(TypeIdentifier::INT); // true 
119+     // define a simple integer type  
120+     $type = Type::int(); 
121+     // check if the  type matches a specific  identifier 
122+     $type->isIdentifiedBy(TypeIdentifier::INT);     // true 
120123    $type->isIdentifiedBy(TypeIdentifier::STRING); // false 
121124
122-     $type = Type::union(Type::string(), Type::int()); // with an union of int and string types 
123-     // You can now see that the second check will pass to true since we have an union with a string type 
124-     $type->isIdentifiedBy(TypeIdentifier::INT); // true 
125+     // define a union type (equivalent to PHP's int|string) 
126+     $type = Type::union(Type::string(), Type::int()); 
127+     // now the second check is true because the union type contains the string type 
128+     $type->isIdentifiedBy(TypeIdentifier::INT);    // true 
125129    $type->isIdentifiedBy(TypeIdentifier::STRING); // true 
126130
127131    class DummyParent {} 
128132    class Dummy extends DummyParent implements DummyInterface {} 
129-     $type = Type::object(Dummy::class); // with an object Type 
130-     // You can check is the Type is an object, or even if it's a given class 
133+ 
134+     // define an object type 
135+     $type = Type::object(Dummy::class); 
136+ 
137+     // check if the type is an object or matches a specific class 
131138    $type->isIdentifiedBy(TypeIdentifier::OBJECT); // true 
132-     $type->isIdentifiedBy(Dummy::class); // true 
133-     // Or  inherits/implements something 
134-     $type->isIdentifiedBy(DummyParent::class); // true 
135-     $type->isIdentifiedBy(DummyInterface::class); // true 
139+     $type->isIdentifiedBy(Dummy::class);            // true 
140+     // check if it  inherits/implements something 
141+     $type->isIdentifiedBy(DummyParent::class);      // true 
142+     $type->isIdentifiedBy(DummyInterface::class);   // true 
136143
137- Sometimes you want to check  for more than one thing at a time so a callable may be better to check everything: :
144+ Using callables  for ** complex checks ** :
138145
139146    class Foo
140147    {
@@ -150,8 +157,7 @@ Sometimes you want to check for more than one thing at a time so a callable may
150157    $stringType = $resolver->resolve($reflClass->getProperty('string'));
151158    $floatType = $resolver->resolve($reflClass->getProperty('float'));
152159
153-     // your callable to check whatever you need 
154-     // here we want to validate a given type is a non nullable number 
160+     // define a callable to validate non-nullable number types
155161    $isNonNullableNumber = function (Type $type): bool {
156162        if ($type->isNullable()) {
157163            return false;
@@ -165,5 +171,5 @@ Sometimes you want to check for more than one thing at a time so a callable may
165171    };
166172
167173    $integerType->isSatisfiedBy($isNonNullableNumber); // true
168-     $stringType->isSatisfiedBy($isNonNullableNumber); // false 
169-     $floatType->isSatisfiedBy($isNonNullableNumber); // false 
174+     $stringType->isSatisfiedBy($isNonNullableNumber);   // false
175+     $floatType->isSatisfiedBy($isNonNullableNumber);    // false
0 commit comments