Skip to content

Commit d522388

Browse files
committed
[TypoInfo] Remove deprecated code for non-array based collections
1 parent 6e4ffa6 commit d522388

File tree

7 files changed

+33
-29
lines changed

7 files changed

+33
-29
lines changed

UPGRADE-8.0.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,19 @@ TwigBundle
481481

482482
* Make `TemplateCacheWarmer` class `final`
483483

484+
TypeInfo
485+
--------
486+
487+
* Constructing a `CollectionType` instance as a list that is not an array throws an `InvalidArgumentException`
488+
* Remove the third `$asList` argument of `TypeFactoryTrait::iterable()`, use `TypeFactoryTrait::list()` instead
489+
490+
```diff
491+
use Symfony\Component\TypeInfo\Type;
492+
493+
-$type = Type::iterable(Type::string(), asList: true);
494+
+$type = Type::list(Type::string());
495+
```
496+
484497
Validator
485498
---------
486499

src/Symfony/Component/TypeInfo/CHANGELOG.md

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

4+
8.0
5+
---
6+
7+
* Constructing a `CollectionType` instance as a list that is not an array throws an `InvalidArgumentException`
8+
* Remove the third `$asList` argument of `TypeFactoryTrait::iterable()`, use `TypeFactoryTrait::list()` instead
9+
10+
```diff
11+
use Symfony\Component\TypeInfo\Type;
12+
13+
-$type = Type::iterable(Type::string(), asList: true);
14+
+$type = Type::list(Type::string());
15+
```
16+
417
7.3
518
---
619

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

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

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1615
use Symfony\Component\TypeInfo\Exception\InvalidArgumentException;
1716
use Symfony\Component\TypeInfo\Type;
1817
use Symfony\Component\TypeInfo\Type\CollectionType;
@@ -21,8 +20,6 @@
2120

2221
class CollectionTypeTest extends TestCase
2322
{
24-
use ExpectUserDeprecationMessageTrait;
25-
2623
public function testCannotCreateInvalidBuiltinType()
2724
{
2825
$this->expectException(InvalidArgumentException::class);
@@ -126,12 +123,11 @@ public function testAccepts()
126123
$this->assertFalse($type->accepts(new \ArrayObject([0 => true, 1 => 'string'])));
127124
}
128125

129-
/**
130-
* @group legacy
131-
*/
132126
public function testCannotCreateIterableList()
133127
{
134-
$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.');
128+
$this->expectException(InvalidArgumentException::class);
129+
$this->expectExceptionMessage('Cannot create a "Symfony\Component\TypeInfo\Type\CollectionType" as list when type is not "array".');
130+
135131
new CollectionType(Type::generic(Type::builtin(TypeIdentifier::ITERABLE), Type::bool()), isList: true);
136132
}
137133

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

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

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
1615
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyBackedEnum;
1716
use Symfony\Component\TypeInfo\Tests\Fixtures\DummyEnum;
1817
use Symfony\Component\TypeInfo\Type;
@@ -31,8 +30,6 @@
3130

3231
class TypeFactoryTest extends TestCase
3332
{
34-
use ExpectUserDeprecationMessageTrait;
35-
3633
public function testCreateBuiltin()
3734
{
3835
$this->assertEquals(new BuiltinType(TypeIdentifier::INT), Type::builtin(TypeIdentifier::INT));
@@ -284,13 +281,4 @@ public function offsetUnset(mixed $offset): void
284281
yield [Type::collection(Type::object(\Generator::class), Type::string(), Type::int()), (fn (): iterable => yield 'string')()];
285282
yield [Type::collection(Type::object($arrayAccess::class)), $arrayAccess];
286283
}
287-
288-
/**
289-
* @group legacy
290-
*/
291-
public function testCannotCreateIterableList()
292-
{
293-
$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.');
294-
Type::iterable(key: Type::int(), asList: true);
295-
}
296284
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public function __construct(
4040

4141
if ($this->isList()) {
4242
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" in 8.0.', self::class, InvalidArgumentException::class);
44-
// throw new InvalidArgumentException(\sprintf('Cannot create a "%s" as list when type is not "array".', self::class));
43+
throw new InvalidArgumentException(\sprintf('Cannot create a "%s" as list when type is not "array".', self::class));
4544
}
4645

4746
$keyType = $this->getCollectionKeyType();

src/Symfony/Component/TypeInfo/TypeFactoryTrait.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,9 @@ public static function array(?Type $value = null, ?Type $key = null, bool $asLis
170170
/**
171171
* @return CollectionType<BuiltinType<TypeIdentifier::ITERABLE>>
172172
*/
173-
public static function iterable(?Type $value = null, ?Type $key = null, bool $asList = false): CollectionType
173+
public static function iterable(?Type $value = null, ?Type $key = null): CollectionType
174174
{
175-
if ($asList) {
176-
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);
177-
}
178-
179-
return self::collection(self::builtin(TypeIdentifier::ITERABLE), $value, $key, $asList);
175+
return self::collection(self::builtin(TypeIdentifier::ITERABLE), $value, $key);
180176
}
181177

182178
/**

src/Symfony/Component/TypeInfo/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
],
2727
"require": {
2828
"php": ">=8.4",
29-
"psr/container": "^1.1|^2.0",
30-
"symfony/deprecation-contracts": "^2.5|^3"
29+
"psr/container": "^1.1|^2.0"
3130
},
3231
"require-dev": {
3332
"phpstan/phpdoc-parser": "^1.30|^2.0"

0 commit comments

Comments
 (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