8000 [TypeInfo] Deprecate creation of `CollectionType` as list and not as … · symfony/symfony@092d211 · GitHub
[go: up one dir, main page]

Skip to content

Commit 092d211

Browse files
committed
[TypeInfo] Deprecate creation of CollectionType as list and not as array
1 parent 78f4d9a commit 092d211

File tree

6 files changed

+37
-10
lines changed

6 files changed

+37
-10
lines changed

UPGRADE-7.3.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
UPGRADE FROM 7.2 to 7.3
2+
=======================
3+
4+
Symfony 7.3 is a minor release. According to the Symfony release process, there should be no significant
5+
backward compatibility breaks. Minor backward compatibility breaks are prefixed in this document with
6+
`[BC BREAK]`, make sure your code is compatible with these entries before upgrading.
7+
Read more about this in the [Symfony documentation](https://symfony.com/doc/7.3/setup/upgrade_minor.html).
8+
9+
If you're upgrading from a version below 7.2, follow the [7.2 upgrade guide](UPGRADE-7.2.md) first.
10+
11+
TypeInfo
12+
--------
13+
14+
* Deprecate creation of `CollectionType` as list and not as array

src/Symfony/Component/TypeInfo/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 creation of `CollectionType` as list and not as array
8+
49
7.2
510
---
611

src/Symfony/Component/TypeInfo/Tests/Type/CollectionTypeTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\TypeInfo\Tests\Type;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1516
use Symfony\Component\TypeInfo\Exception\InvalidArgumentException;
1617
use Symfony\Component\TypeInfo\Type;
1718
use Symfony\Component\TypeInfo\Type\CollectionType;
@@ -20,6 +21,8 @@
2021

2122
class CollectionTypeTest extends TestCase
2223
{
24+
use ExpectUserDeprecationMessageTrait;
25+
2326
public function testCannotCreateInvalidBuiltinType()
2427
{
2528
$this->expectException(InvalidArgumentException::class);
@@ -88,4 +91,13 @@ public function testToString()
8891
$type = new CollectionType(new GenericType(Type::builtin(TypeIdentifier::ARRAY), Type::string(), Type::bool()));
8992
$this->assertEquals('array<string,bool>', (string) $type);
9093
}
94+
95+
/**
96+
* @group legacy
97+
*/
98+
public function testCannotCreateIterableList()
99+
{
100+
$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" exception in 8.0.');
101+
new CollectionType(Type::generic(Type::builtin(TypeIdentifier::ITERABLE), Type::bool()), isList: true);
102+
}
91103
}

src/Symfony/Component/TypeInfo/Tests/TypeFactoryTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,6 @@ public function testCreateIterable()
136136
)),
137137
Type::iterable(Type::bool(), Type::string()),
138138
);
139-
140-
$this->assertEquals(
141-
new CollectionType(new GenericType(
142-
new BuiltinType(TypeIdentifier::ITERABLE),
143-
new BuiltinType(TypeIdentifier::INT),
144-
new BuiltinType(TypeIdentifier::BOOL),
145-
), isList: true),
146-
Type::iterable(Type::bool(), Type::int(), true),
147-
);
148139
}
149140

150141
public function testCreateObject()

src/Symfony/Component/TypeInfo/Type/CollectionType.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public function __construct(
3939
}
4040

4141
if ($this->isList()) {
42+
if (!$type->isIdentifiedBy(TypeIdentifier::ARRAY)) {
43+
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" exception in 8.0.', self::class, InvalidArgumentException::class);
44+
}
45+
4246
$keyType = $this->getCollectionKeyType();
4347

4448
if (!$keyType instanceof BuiltinType || TypeIdentifier::INT !== $keyType->getTypeIdentifier()) {

src/Symfony/Component/TypeInfo/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
],
2727
"require": {
2828
"php": ">=8.2",
29-
"psr/container": "^1.1|^2.0"
29+
"psr/container": "^1.1|^2.0",
30+
"symfony/deprecation-contracts": "^2.5|^3"
3031
},
3132
"require-dev": {
3233
"phpstan/phpdoc-parser": "^1.0|^2.0"

0 commit comments

Comments
 (0)
0