From d522388adfd0760400629ab7cbe5714d73b665b2 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Mon, 30 Jun 2025 19:41:25 +0200 Subject: [PATCH] [TypoInfo] Remove deprecated code for non-array based collections --- UPGRADE-8.0.md | 13 +++++++++++++ src/Symfony/Component/TypeInfo/CHANGELOG.md | 13 +++++++++++++ .../TypeInfo/Tests/Type/CollectionTypeTest.php | 10 +++------- .../Component/TypeInfo/Tests/TypeFactoryTest.php | 12 ------------ .../Component/TypeInfo/Type/CollectionType.php | 3 +-- src/Symfony/Component/TypeInfo/TypeFactoryTrait.php | 8 ++------ src/Symfony/Component/TypeInfo/composer.json | 3 +-- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/UPGRADE-8.0.md b/UPGRADE-8.0.md index 0cc7a51882305..05a9b5b8f49a4 100644 --- a/UPGRADE-8.0.md +++ b/UPGRADE-8.0.md @@ -481,6 +481,19 @@ TwigBundle * Make `TemplateCacheWarmer` class `final` +TypeInfo +-------- + + * Constructing a `CollectionType` instance as a list that is not an array throws an `InvalidArgumentException` + * Remove the third `$asList` argument of `TypeFactoryTrait::iterable()`, use `TypeFactoryTrait::list()` instead + + ```diff + use Symfony\Component\TypeInfo\Type; + + -$type = Type::iterable(Type::string(), asList: true); + +$type = Type::list(Type::string()); + ``` + Validator --------- diff --git a/src/Symfony/Component/TypeInfo/CHANGELOG.md b/src/Symfony/Component/TypeInfo/CHANGELOG.md index a8c96108c7f51..296463cd31a82 100644 --- a/src/Symfony/Component/TypeInfo/CHANGELOG.md +++ b/src/Symfony/Component/TypeInfo/CHANGELOG.md @@ -1,6 +1,19 @@ CHANGELOG ========= +8.0 +--- + + * Constructing a `CollectionType` instance as a list that is not an array throws an `InvalidArgumentException` + * Remove the third `$asList` argument of `TypeFactoryTrait::iterable()`, use `TypeFactoryTrait::list()` instead + + ```diff + use Symfony\Component\TypeInfo\Type; + + -$type = Type::iterable(Type::string(), asList: true); + +$type = Type::list(Type::string()); + ``` + 7.3 --- diff --git a/src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php b/src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php index 2b8d6031efdcc..892bbdd015288 100644 --- a/src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php +++ b/src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\TypeInfo\Tests\Type; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait; use Symfony\Component\TypeInfo\Exception\InvalidArgumentException; use Symfony\Component\TypeInfo\Type; use Symfony\Component\TypeInfo\Type\CollectionType; @@ -21,8 +20,6 @@ class CollectionTypeTest extends TestCase { - use ExpectUserDeprecationMessageTrait; - public function testCannotCreateInvalidBuiltinType() { $this->expectException(InvalidArgumentException::class); @@ -126,12 +123,11 @@ public function testAccepts() $this->assertFalse($type->accepts(new \ArrayObject([0 => true, 1 => 'string']))); } - /** - * @group legacy - */ public function testCannotCreateIterableList() { - $this->expectUserDeprecationMessage('Since symfony/type-info 7.3: Creating a "Symfony\Component\TypeInfo\Type\CollectionType" that is a list and not an array is deprecated and will throw a "Symfony\Component\TypeInfo\Exception\InvalidArgumentException" in 8.0.'); + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Cannot create a "Symfony\Component\TypeInfo\Type\CollectionType" as list when type is not "array".'); + new CollectionType(Type::generic(Type::builtin(TypeIdentifier::ITERABLE), Type::bool()), isList: true); } diff --git a/src/Symfony/Component/TypeInfo/Tests/TypeFactoryTest.php b/src/Symfony/Component/TypeInfo/Tests/TypeFactoryTest.php index 6a9aaf4cfe25b..9abf574491634 100644 --- a/src/Symfony/Component/TypeInfo/Tests/TypeFactoryTest.php +++ b/src/Symfony/Component/TypeInfo/Tests/TypeFactoryTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\TypeInfo\Tests; use PHPUnit\Framework\TestCase; -use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyBackedEnum; use Symfony\Component\TypeInfo\Tests\Fixtures\DummyEnum; use Symfony\Component\TypeInfo\Type; @@ -31,8 +30,6 @@ class TypeFactoryTest extends TestCase { - use ExpectUserDeprecationMessageTrait; - public function testCreateBuiltin() { $this->assertEquals(new BuiltinType(TypeIdentifier::INT), Type::builtin(TypeIdentifier::INT)); @@ -284,13 +281,4 @@ public function offsetUnset(mixed $offset): void yield [Type::collection(Type::object(\Generator::class), Type::string(), Type::int()), (fn (): iterable => yield 'string')()]; yield [Type::collection(Type::object($arrayAccess::class)), $arrayAccess]; } - - /** - * @group legacy - */ - public function testCannotCreateIterableList() - { - $this->expectUserDeprecationMessage('Since symfony/type-info 7.3: The third argument of "Symfony\Component\TypeInfo\TypeFactoryTrait::iterable()" is deprecated. Use the "Symfony\Component\TypeInfo\Type::list()" method to create a list instead.'); - Type::iterable(key: Type::int(), asList: true); - } } diff --git a/src/Symfony/Component/TypeInfo/Type/CollectionType.php b/src/Symfony/Component/TypeInfo/Type/CollectionType.php index a801f2b51f8d0..95f52864a598f 100644 --- a/src/Symfony/Component/TypeInfo/Type/CollectionType.php +++ b/src/Symfony/Component/TypeInfo/Type/CollectionType.php @@ -40,8 +40,7 @@ public function __construct( if ($this->isList()) { if (!$type->isIdentifiedBy(TypeIdentifier::ARRAY)) { - trigger_deprecation('symfony/type-info', '7.3', 'Creating a "%s" that is a list and not an array is deprecated and will throw a "%s" in 8.0.', self::class, InvalidArgumentException::class); - // throw new InvalidArgumentException(\sprintf('Cannot create a "%s" as list when type is not "array".', self::class)); + throw new InvalidArgumentException(\sprintf('Cannot create a "%s" as list when type is not "array".', self::class)); } $keyType = $this->getCollectionKeyType(); diff --git a/src/Symfony/Component/TypeInfo/TypeFactoryTrait.php b/src/Symfony/Component/TypeInfo/TypeFactoryTrait.php index b922c2749ba5d..782a236a83274 100644 --- a/src/Symfony/Component/TypeInfo/TypeFactoryTrait.php +++ b/src/Symfony/Component/TypeInfo/TypeFactoryTrait.php @@ -170,13 +170,9 @@ public static function array(?Type $value = null, ?Type $key = null, bool $asLis /** * @return CollectionType> */ - public static function iterable(?Type $value = null, ?Type $key = null, bool $asList = false): CollectionType + public static function iterable(?Type $value = null, ?Type $key = null): CollectionType { - if ($asList) { - trigger_deprecation('symfony/type-info', '7.3', 'The third argument of "%s()" is deprecated. Use the "%s::list()" method to create a list instead.', __METHOD__, self::class); - } - - return self::collection(self::builtin(TypeIdentifier::ITERABLE), $value, $key, $asList); + return self::collection(self::builtin(TypeIdentifier::ITERABLE), $value, $key); } /** diff --git a/src/Symfony/Component/TypeInfo/composer.json b/src/Symfony/Component/TypeInfo/composer.json index 29f59bec297c1..8a5693a38c846 100644 --- a/src/Symfony/Component/TypeInfo/composer.json +++ b/src/Symfony/Component/TypeInfo/composer.json @@ -26,8 +26,7 @@ ], "require": { "php": ">=8.4", - "psr/container": "^1.1|^2.0", - "symfony/deprecation-contracts": "^2.5|^3" + "psr/container": "^1.1|^2.0" }, "require-dev": { "phpstan/phpdoc-parser": "^1.30|^2.0" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy