Skip to content

[PropertyInfo] remove deprecations, mark TypeInfo as experimental #54789

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 1 commit into from
May 2, 2024
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
39 changes: 0 additions & 39 deletions UPGRADE-7.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,45 +81,6 @@ Mailer

* Postmark's "406 - Inactive recipient" API error code now results in a `PostmarkDeliveryEvent` instead of throwing a `HttpTransportException`

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

* Deprecate the `Type` class, use `Symfony\Component\TypeInfo\Type` class of `symfony/type-info` component instead

*Before*
```php
use Symfony\Component\PropertyInfo\Type;

// bool
$boolType = new Type(LegacyType::BUILTIN_TYPE_BOOL);
// bool|null
$nullableType = new Type(LegacyType::BUILTIN_TYPE_BOOL, nullable: true);
// array<int, string|null>
$arrayType = new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING, true));

$arrayType->getBuiltinType(); // returns "array"
$arrayType->getCollectionKeyTypes(); // returns an array with an "int" Type instance
$arrayType->getCollectionValueTypes()[0]->isNullable(); // returns true
```

*After*
```php
use Symfony\Component\TypeInfo\Type;

// bool
$boolType = Type::bool();
// bool|null
$nullableType = Type::nullable(Type::bool());
// array<int, string|null>
$arrayType = Type::array(Type::nullable(Type::string()), Type::int());

(string) $arrayType->getBaseType(); // returns "array"
$arrayType->getCollectionKeyType(); // returns an "int" Type instance
$arrayType->getCollectionValueType()->isNullable(); // returns true
```

* Deprecate `PropertyTypeExtractorInterface::getTypes()`, use `PropertyTypeExtractorInterface::getType()` instead

HttpKernel
----------

Expand Down
3 changes: 1 addition & 2 deletions src/Symfony/Component/PropertyInfo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ CHANGELOG

* Introduce `PropertyDocBlockExtractorInterface` to extract a property's doc block
* Restrict access to `PhpStanExtractor` based on visibility
* Deprecate the `Type` class, use `Symfony\Component\TypeInfo\Type` class of `symfony/type-info` component instead
* Deprecate the `PropertyTypeExtractorInterface::getTypes()` method, use `PropertyTypeExtractorInterface::getType()` instead
* Add `PropertyTypeExtractorInterface::getType()` as experimental

6.4
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public function __construct(
) {
}

/**
* @experimental
*/
public function getType(string $class, string $property, array $context = []): ?Type
{
foreach ($this->extractors as $extractor) {
Expand All @@ -40,13 +43,8 @@ public function getType(string $class, string $property, array $context = []): ?
return null;
}

/**
* @deprecated since Symfony 7.1, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.1', '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,13 +118,8 @@ public function getLongDescription(string $class, string $property, array $conte
return '' === $contents ? null : $contents;
}

/**
* @deprecated since Symfony 7.1, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.1', '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 @@ -176,13 +171,8 @@ 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.1, use "getTypeFromConstructor" instead
*/
public function getTypesFromConstructor(string $class, string $property): ?array
{
trigger_deprecation('symfony/property-info', '7.1', 'The "%s()" method is deprecated, use "%s::getTypeFromConstructor()" instead.', __METHOD__, self::class);

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

if (!$docBlock) {
Expand All @@ -204,6 +194,9 @@ public function getTypesFromConstructor(string $class, string $property): ?array
return array_merge([], ...$types);
}

/**
* @experimental
*/
public function getType(string $class, string $property, array $context = []): ?Type
{
/** @var $docBlock DocBlock */
Expand Down Expand Up @@ -263,6 +256,9 @@ public function getType(string $class, string $property, array $context = []): ?
return Type::list($type);
}

/**
* @experimental
*/
public function getTypeFromConstructor(string $class, string $property): ?Type
{
if (!$docBlock = $this->getDocBlockFromConstructor($class, $property)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,8 @@ public function __construct(?array $mutatorPrefixes = null, ?array $accessorPref
$this->typeContextFactory = new TypeContextFactory($this->stringTypeResolver);
}

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

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

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

if (null === $tagDocNode = $this->getDocBlockFromConstructor($class, $property)) {
return null;
}
Expand All @@ -183,6 +174,9 @@ public function getTypesFromConstructor(string $class, string $property): ?array
return $types;
}

/**
* @experimental
*/
public function getType(string $class, string $property, array $context = []): ?Type
{
/** @var PhpDocNode|null $docNode */
Expand Down Expand Up @@ -229,6 +223,9 @@ public function getType(string $class, string $property, array $context = []): ?
return Type::list($type);
}

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

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

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

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

try {
$reflection = new \ReflectionClass($class);
} catch (\ReflectionException) {
Expand All @@ -199,6 +190,9 @@ public function getTypesFromConstructor(string $class, string $property): ?array
return $types;
}

/**
* @experimental
*/
public function getType(string $class, string $property, array $context = []): ?Type
{
[$mutatorReflection, $prefix] = $this->getMutatorMethod($class, $property);
Expand Down Expand Up @@ -260,6 +254,9 @@ public function getType(string $class, string $property, array $context = []): ?
return $type;
}

/**
* @experimental
*/
public function getTypeFromConstructor(string $class, string $property): ?Type
{
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ public function getProperties(string $class, array $context = []): ?array
return $this->extract('getProperties', [$class, $context]);
}

/**
* @experimental
*/
public function getType(string $class, string $property, array $context = []): ?Type
{
return $this->extract('getType', [$class, $property, $context]);
Expand All @@ -66,8 +69,6 @@ public function getType(string $class, string $property, array $context = []): ?
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.1', '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 @@ -53,18 +53,16 @@ public function getLongDescription(string $class, string $property, array $conte
return $this->extract($this->descriptionExtractors, 'getLongDescription', [$class, $property, $context]);
}

/**
* @experimental
*/
public function getType(string $class, string $property, array $context = []): ?Type
{
return $this->extract($this->typeExtractors, 'getType', [$class, $property, $context]);
}

/**
* @deprecated since Symfony 7.1, use "getType" instead
*/
public function getTypes(string $class, string $property, array $context = []): ?array
{
trigger_deprecation('symfony/property-info', '7.1', '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,8 +26,6 @@ interface PropertyTypeExtractorInterface
/**
* Gets types of a property.
*
* @deprecated since Symfony 7.1, use "getType" instead
*
* @return LegacyType[]|null
*/
public function getTypes(string $class, string $property, array $context = []): ?array;
Expand Down
4 changes: 0 additions & 4 deletions src/Symfony/Component/PropertyInfo/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@

namespace Symfony\Component\PropertyInfo;

trigger_deprecation('symfony/property-info', '7.1', 'The "%s" class is deprecated. Use "%s" from the "symfony/type-info" component instead.', Type::class, \Symfony\Component\TypeInfo\Type::class);

/**
* Type value object (immutable).
*
* @author Kévin Dunglas <dunglas@gmail.com>
*
* @deprecated since Symfony 7.1, use "Symfony\Component\TypeInfo\Type" from the "symfony/type-info" component instead
*
* @final
*/
class Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@ final class PhpDocTypeHelper
/**
* Creates a {@see LegacyType} from a PHPDoc type.
*
* @deprecated since Symfony 7.1, use "getType" instead
*
* @return LegacyType[]
*/
public function getTypes(DocType $varType): array
{
trigger_deprecation('symfony/property-info', '7.1', 'The "%s()" method is deprecated, use "%s::getType()" instead.', __METHOD__, self::class);

if ($varType instanceof ConstExpression) {
// It's safer to fall back to other extractors here, as resolving const types correctly is not easy at the moment
return [];
Expand Down Expand Up @@ -110,6 +106,8 @@ public function getTypes(DocType $varType): array

/**
* Creates a {@see Type} from a PHPDoc type.
*
* @experimental
*/
public function getType(DocType $varType): ?Type
{
Expand Down
Loading