Skip to content

[PropertyInfo] Deprecate Type #59902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions UPGRADE-7.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ DependencyInjection

* Deprecate `ContainerBuilder::getAutoconfiguredAttributes()` in favor of the `getAttributeAutoconfigurators()` method.

DoctrineBridge
--------------

* Deprecate the `DoctrineExtractor::getTypes()` method, use `DoctrineExtractor::getType()` instead

FrameworkBundle
---------------

Expand Down Expand Up @@ -76,6 +81,13 @@ OptionsResolver
});
```

PropertyInfo
------------

* Deprecate the `Type` class, use `Symfony\Component\TypeInfo\Type` class from `symfony/type-info` instead
* Deprecate the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead
* Deprecate the `ConstructorArgumentTypeExtractorInterface::getTypesFromConstructor()` method, use `ConstructorArgumentTypeExtractorInterface::getTypeFromConstructor()` instead

Security
--------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/Doctrine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Reset the manager registry using native lazy objects when applicable
* Deprecate the `DoctrineExtractor::getTypes()` method, use `DoctrineExtractor::getType()` instead

7.2
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,13 @@ public function getType(string $class, string $property, array $context = []): ?
};
}

/**
* @deprecated since Symfony 7.3, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);

if (null === $metadata = $this->getMetadata($class)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded;
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumInt;
use Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\EnumString;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\PropertyInfo\Type as LegacyType;
use Symfony\Component\TypeInfo\Type;

Expand All @@ -38,6 +39,8 @@
*/
class DoctrineExtractorTest extends TestCase
{
use ExpectDeprecationTrait;

private function createExtractor(): DoctrineExtractor
{
$config = ORMSetup::createConfiguration(true);
Expand Down Expand Up @@ -108,15 +111,24 @@ public function testTestGetPropertiesWithEmbedded()
}

/**
* @group legacy
*
* @dataProvider legacyTypesProvider
*/
public function testExtractLegacy(string $property, ?array $type = null)
{
$this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getTypes()" method is deprecated, use "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getType()" instead.');

$this->assertEquals($type, $this->createExtractor()->getTypes(DoctrineDummy::class, $property, []));
}

/**
* @group legacy
*/
public function testExtractWithEmbeddedLegacy()
{
$this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getTypes()" method is deprecated, use "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getType()" instead.');

$expectedTypes = [new LegacyType(
LegacyType::BUILTIN_TYPE_OBJECT,
false,
Expand All @@ -132,15 +144,23 @@ public function testExtractWithEmbeddedLegacy()
$this->assertEquals($expectedTypes, $actualTypes);
}

/**
* @group legacy
*/
public function testExtractEnumLegacy()
{
$this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getTypes()" method is deprecated, use "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getType()" instead.');

$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, EnumString::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumString', []));
$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_OBJECT, false, EnumInt::class)], $this->createExtractor()->getTypes(DoctrineEnum::class, 'enumInt', []));
$this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumStringArray', []));
$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', []));
$this->assertNull($this->createExtractor()->getTypes(DoctrineEnum::class, 'enumCustom', []));
}

/**
* @group legacy
*/
public static function legacyTypesProvider(): array
{
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
Expand Down Expand Up @@ -240,8 +260,13 @@ public function testGetPropertiesCatchException()
$this->assertNull($this->createExtractor()->getProperties('Not\Exist'));
}

/**
* @group legacy
*/
public function testGetTypesCatchExceptionLegacy()
{
$this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getTypes()" method is deprecated, use "Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor::getType()" instead.');

$this->assertNull($this->createExtractor()->getTypes('Not\Exist', 'baz'));
}

Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/PropertyInfo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ CHANGELOG

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

7.1
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ interface ConstructorArgumentTypeExtractorInterface
/**
* Gets types of an argument from constructor.
*
* @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead
*
* @return LegacyType[]|null
*/
public function getTypesFromConstructor(string $class, string $property): ?array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ public function getType(string $class, string $property, array $context = []): ?
return null;
}

/**
* @deprecated since Symfony 7.3, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);

foreach ($this->extractors as $extractor) {
$value = $extractor->getTypesFromConstructor($class, $property);
if (null !== $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ public function getLongDescription(string $class, string $property, array $conte
return '' === $contents ? null : $contents;
}

/**
* @deprecated since Symfony 7.3, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);

/** @var DocBlock $docBlock */
[$docBlock, $source, $prefix] = $this->findDocBlock($class, $property);
if (!$docBlock) {
Expand Down Expand Up @@ -171,8 +176,13 @@ public function getTypes(string $class, string $property, array $context = []):
return [new LegacyType(LegacyType::BUILTIN_TYPE_ARRAY, false, null, true, new LegacyType(LegacyType::BUILTIN_TYPE_INT), $types[0])];
}

/**
* @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead
*/
public function getTypesFromConstructor(string $class, string $property): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class);

$docBlock = $this->getDocBlockFromConstructor($class, $property);

if (!$docBlock) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ public function __construct(?array $mutatorPrefixes = null, ?array $accessorPref
$this->typeContextFactory = new TypeContextFactory($this->stringTypeResolver);
}

/**
* @deprecated since Symfony 7.3, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);

/** @var PhpDocNode|null $docNode */
[$docNode, $source, $prefix, $declaringClass] = $this->getDocBlock($class, $property);
if (null === $docNode) {
Expand Down Expand Up @@ -168,10 +173,14 @@ public function getTypes(string $class, string $property, array $context = []):
}

/**
* @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead
*
* @return LegacyType[]|null
*/
public function getTypesFromConstructor(string $class, string $property): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class);

if (null === $tagDocNode = $this->getDocBlockFromConstructor($class, $property)) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ public function getProperties(string $class, array $context = []): ?array
return $properties ? array_values($properties) : null;
}

/**
* @deprecated since Symfony 7.3, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);

if ($fromMutator = $this->extractFromMutator($class, $property)) {
return $fromMutator;
}
Expand All @@ -180,10 +185,14 @@ public function getTypes(string $class, string $property, array $context = []):
}

/**
* @deprecated since Symfony 7.3, use "getTypeFromConstructor" instead
*
* @return LegacyType[]|null
*/
public function getTypesFromConstructor(string $class, string $property): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class);

try {
$reflection = new \ReflectionClass($class);
} catch (\ReflectionException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ public function getType(string $class, string $property, array $context = []): ?
return $this->arrayCache[$key] = $value;
}

/**
* @deprecated since Symfony 7.3, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);

return $this->extract('getTypes', [$class, $property, $context]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ public function getType(string $class, string $property, array $context = []): ?
return null;
}

/**
* @deprecated since Symfony 7.3, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.3', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);

return $this->extract($this->typeExtractors, 'getTypes', [$class, $property, $context]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface PropertyTypeExtractorInterface
/**
* Gets types of a property.
*
* @deprecated since Symfony 7.3, use "getType" instead
*
* @return LegacyType[]|null
*/
public function getTypes(string $class, string $property, array $context = []): ?array;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\PropertyInfo\Tests\Extractor;

use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor;
use Symfony\Component\PropertyInfo\Tests\Fixtures\DummyExtractor;
use Symfony\Component\PropertyInfo\Type as LegacyType;
Expand All @@ -22,6 +23,8 @@
*/
class ConstructorExtractorTest extends TestCase
{
use ExpectDeprecationTrait;

private ConstructorExtractor $extractor;

protected function setUp(): void
Expand Down Expand Up @@ -50,6 +53,8 @@ public function testGetTypeIfNoExtractors()
*/
public function testGetTypes()
{
$this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor::getType()" instead.');

$this->assertEquals([new LegacyType(LegacyType::BUILTIN_TYPE_STRING)], $this->extractor->getTypes('Foo', 'bar', []));
}

Expand All @@ -58,6 +63,8 @@ public function testGetTypes()
*/
public function testGetTypesIfNoExtractors()
{
$this->expectDeprecation('Since symfony/property-info 7.3: The "Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor::getTypes()" method is deprecated, use "Symfony\Component\PropertyInfo\Extractor\ConstructorExtractor::getType()" instead.');

$extractor = new ConstructorExtractor([]);
$this->assertNull($extractor->getTypes('Foo', 'bar', []));
}
Expand Down
Loading
Loading