Skip to content

Commit fc6186c

Browse files
committed
bug symfony#59145 [TypeInfo] Make Type::nullable method no-op on every nullable type (mtarld)
This PR was merged into the 7.2 branch. Discussion ---------- [TypeInfo] Make `Type::nullable` method no-op on every nullable type | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Issues | Fix symfony#59137 | License | MIT Make `Type::nullable` method no-op on every nullable type, not only on `NullableType` types. Commits ------- 640a8d5 [TypeInfo] Fix handle nullable with mixed
2 parents 59597c8 + 640a8d5 commit fc6186c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public function testCreateNullable()
195195
{
196196
$this->assertEquals(new NullableType(new BuiltinType(TypeIdentifier::INT)), Type::nullable(Type::int()));
197197
$this->assertEquals(new NullableType(new BuiltinType(TypeIdentifier::INT)), Type::nullable(Type::nullable(Type::int())));
198+
$this->assertEquals(new BuiltinType(TypeIdentifier::MIXED), Type::nullable(Type::mixed()));
198199

199200
$this->assertEquals(
200201
new NullableType(new UnionType(new BuiltinType(TypeIdentifier::INT), new BuiltinType(TypeIdentifier::STRING))),

src/Symfony/Component/TypeInfo/TypeFactoryTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,11 @@ public static function intersection(Type ...$types): IntersectionType
330330
*
331331
* @param T $type
332332
*
333-
* @return ($type is NullableType ? T : NullableType<T>)
333+
* @return T|NullableType<T>
334334
*/
335-
public static function nullable(Type $type): NullableType
335+
public static function nullable(Type $type): Type
336336
{
337-
if ($type instanceof NullableType) {
337+
if ($type->isNullable()) {
338338
return $type;
339339
}
340340

0 commit comments

Comments
 (0)