Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9d3291

Browse files
committed
[PropertyInfo] Deprecate Type
1 parent 3590ca3 commit a9d3291

21 files changed

+222
-0
lines changed

UPGRADE-7.3.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ Console
8888

8989
* Deprecate methods `Command::getDefaultName()` and `Command::getDefaultDescription()` in favor of the `#[AsCommand]` attribute
9090

91+
DoctrineBridge
92+
--------------
93+
94+
* Deprecate the `DoctrineExtractor::getTypes()` method, use `DoctrineExtractor::getType()` instead
95+
9196
FrameworkBundle
9297
---------------
9398

@@ -115,6 +120,13 @@ OptionsResolver
115120
});
116121
```
117122

123+
PropertyInfo
124+
-------
125+
126+
* Deprecate the `Type` class, use `Symfony\Component\TypeInfo\Type` class of `symfony/type-info` component instead
127+
* Deprecate the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead
128+
* Deprecate the `ConstructorArgumentTypeExtractorInterface::getTypesFromConstructor()` method, use `ConstructorArgumentTypeExtractorInterface::getTypeFromConstructor()` instead
129+
118130
SecurityBundle
119131
--------------
120132

src/Symfony/Bridge/Doctrine/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Deprecate the `DoctrineExtractor::getTypes()` method, use `DoctrineExtractor::getType()` instead
8+
49
7.2
510
---
611

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,13 @@ public function getType(string $class, string $property, array $context = []): ?
161161
};
162162
}
163163

164+
/**
165+
* @deprecated since Symfony 7.3, use "getType" instead
166+
*/
164167
public function getTypes(string $class, string $property, array $context = []): ?array
165168
{
169+
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);
170+
166171
if (null === $metadata = $this->getMetadata($class)) {
167172
return null;
168173
}

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded;
3131
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumInt;
3232
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumString;
33+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
3334
use Symfony\Component\PropertyInfo\Type as LegacyType;
3435
use Symfony\Component\TypeInfo\Type;
3536

@@ -38,6 +39,8 @@
3839
*/
3940
class DoctrineExtractorTest extends TestCase
4041
{
42+
use ExpectDeprecationTrait;
43+
4144
private function createExtractor(): DoctrineExtractor
4245
{
4346
$config = ORMSetup::createConfiguration(true);
@@ -108,15 +111,24 @@ public function testTestGetPropertiesWithEmbedded()
108111
}
109112

110113
/**
114+
* @group legacy
115+
*
111116
* @dataProvider legacyTypesProvider
112117
*/
113118
public function testExtractLegacy(string $property, ?array $type = null)
114119
{
120+
$this->expectDeprecation(sprintf('Since symfony/property-info 7.3: The "%s::getTypes()" method is deprecated, use "%s::getType()" instead.', DoctrineExtractor::class, DoctrineExtractor::class));
121+
115122
$this->assertEquals($type, $this->createExtractor()->getTypes(DoctrineDummy::class, $property, []));
116123
}
117124

125+
/**
126+
* @group legacy
127+
*/
118128
public function testExtractWithEmbeddedLegacy()
119129
{
130+
$this->expectDeprecation(sprintf('Since symfony/property-info 7.3: The "%s::getTypes()" method is deprecated, use "%s::getType()" instead.', DoctrineExtractor::class, DoctrineExtractor::class));
131+
120132
$expectedTypes = [new LegacyType(
121133
LegacyType::BUILTIN_TYPE_OBJECT,
122134
false,
@@ -132,15 +144,23 @@ public function testExtractWithEmbeddedLegacy()
132144
$this->assertEquals($expectedTypes, $actualTypes);
133145
}
134146

147+
/**
148+
* @group legacy
149+
*/
135150
public function testExtractEnumLegacy()
136151
{
152+
$this->expectDeprecation(sprintf('Since symfony/property-info 7.3: The "%s::getTypes()" method is deprecated, use "%s::getType()" instead.', DoctrineExtractor::class, DoctrineExtractor::class));
153+
137154
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, EnumString::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumString', []));
138155
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, EnumInt::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumInt', []));
139156
$this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumStringArray', []));
140157
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, EnumInt::class))], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumIntArray', []));
141158
$this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumCustom', []));
142159
}
143160

161+
/**
162+
* @group legacy
163+
*/
144164
public static function legacyTypesProvider(): array
145165
{
146166
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
@@ -240,8 +260,13 @@ public function testGetPropertiesCatchException()
240260
$this->assertNull($this->createExtractor()->getProperties('Not\Exist'));
241261
}
242262

263+
/**
264+
* @group legacy
265+
*/
243266
public function testGetTypesCatchExceptionLegacy()
244267
{
268+
$this->expectDeprecation(sprintf('Since symfony/property-info 7.3: The "%s::getTypes()" method is deprecated, use "%s::getType()" instead.', DoctrineExtractor::class, DoctrineExtractor::class));
269+
245270
$this->assertNull($this->createExtractor()->getTypes('Not\Exist', 'baz'));
246271
}
247272

src/Symfony/Component/PropertyInfo/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ CHANGELOG
66

77
* Add support for `non-positive-int`, `non-negative-int` and `non-zero-int` PHPStan types to `PhpStanExtractor`
88
* Add `PropertyDescriptionExtractorInterface` to `PhpStanExtractor`
9+
* Deprecate the `Type` class, use `Symfony\Component\TypeInfo\Type` class of `symfony/type-info` component instead
10+
* Deprecate the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead
11+
* Deprecate the `ConstructorArgumentTypeExtractorInterface::getTypesFromConstructor()` method, use `ConstructorArgumentTypeExtractorInterface::getTypeFromConstructor()` instead
912

1013
7.1
1114
---

src/Symfony/Component/PropertyInfo/Extractor/ConstructorArgumentTypeExtractorInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface ConstructorArgumentTypeExtractorInterface
2424
/**
2525
* Gets types of an argument from constructor.
2626
*
27+
* @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead
28+
*
2729
* @return LegacyType[]|null
2830
*/
2931
public function getTypesFromConstructor(string $class, string $property): ?array;

src/Symfony/Component/PropertyInfo/Extractor/ConstructorExtractor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@ public function getType(string $class, string $property, array $context = []): ?
4040
return null;
4141
}
4242

43+
/**
44+
* @deprecated since Symfony 7.3, use "getType" instead
45+
*/
4346
public function getTypes(string $class, string $property, array $context = []): ?array
4447
{
48+
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);
49+
4550
foreach ($this->extractors as $extractor) {
4651
$value = $extractor->getTypesFromConstructor($class, $property);
4752
if (null !== $value) {

src/Symfony/Component/PropertyInfo/Extractor/PhpDocExtractor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,13 @@ public function getLongDescription(string $class, string $property, array $conte
118118
return '' === $contents ? null : $contents;
119119
}
120120

121+
/**
122+
* @deprecated since Symfony 7.3, use "getType" instead
123+
*/
121124
public function getTypes(string $class, string $property, array $context = []): ?array
122125
{
126+
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);
127+
123128
/** @var DocBlock $docBlock */
124129
[$docBlock, $source, $prefix] = $this->findDocBlock($class, $property);
125130
if (!$docBlock) {
@@ -171,8 +176,13 @@ public function getTypes(string $class, string $property, array $context = []):
171176
return [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $types[0])];
172177
}
173178

179+
/**
180+
* @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead
181+
*/
174182
public function getTypesFromConstructor(string $class, string $property): ?array
175183
{
184+
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class);
185+
176186
$docBlock = $this->getDocBlockFromConstructor($class, $property);
177187

178188
if (!$docBlock) {

src/Symfony/Component/PropertyInfo/Extractor/PhpStanExtractor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ public function __construct(?array $mutatorPrefixes = null, ?array $accessorPref
9393
$this->typeContextFactory = new TypeContextFactory($this->stringTypeResolver);
9494
}
9595

96+
/**
97+
* @deprecated since Symfony 7.3, use "getType" instead
98+
*/
9699
public function getTypes(string $class, string $property, array $context = []): ?array
97100
{
101+
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);
102+
98103
/** @var PhpDocNode|null $docNode */
99104
[$docNode, $source, $prefix, $declaringClass] = $this->getDocBlock($class, $property);
100105
if (null === $docNode) {
@@ -166,10 +171,14 @@ public function getTypes(string $class, string $property, array $context = []):
166171
}
167172

168173
/**
174+
* @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead
175+
*
169176
* @return LegacyType[]|null
170177
*/
171178
public function getTypesFromConstructor(string $class, string $property): ?array
172179
{
180+
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class);
181+
173182
if (null === $tagDocNode = $this->getDocBlockFromConstructor($class, $property)) {
174183
return null;
175184
}

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,13 @@ public function getProperties(string $class, array $context = []): ?array
155155
return $properties ? array_values($properties) : null;
156156
}
157157

158+
/**
159+
* @deprecated since Symfony 7.3, use "getType" instead
160+
*/
158161
public function getTypes(string $class, string $property, array $context = []): ?array
159162
{
163+
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);
164+
160165
if ($fromMutator = $this->extractFromMutator($class, $property)) {
161166
return $fromMutator;
162167
}
@@ -180,10 +185,14 @@ public function getTypes(string $class, string $property, array $context = []):
180185
}
181186

182187
/**
188+
* @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead
189+
*
183190
* @return LegacyType[]|null
184191
*/
185192
public function getTypesFromConstructor(string $class, string $property): ?array
186193
{
194+
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class);
195+
187196
try {
188197
$reflection = new \ReflectionClass($class);
189198
} catch (\ReflectionException) {

0 commit comments

Comments
 (0)