Skip to content

Commit

Permalink
bug symfony#59145 [TypeInfo] Make Type::nullable method no-op on ev…
Browse files Browse the repository at this point in the history
…ery 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
  • Loading branch information
fabpot committed Dec 11, 2024
2 parents 59597c8 + 640a8d5 commit fc6186c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/TypeInfo/Tests/TypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public function testCreateNullable()
{
$this->assertEquals(new NullableType(new BuiltinType(TypeIdentifier::INT)), Type::nullable(Type::int()));
$this->assertEquals(new NullableType(new BuiltinType(TypeIdentifier::INT)), Type::nullable(Type::nullable(Type::int())));
$this->assertEquals(new BuiltinType(TypeIdentifier::MIXED), Type::nullable(Type::mixed()));

$this->assertEquals(
new NullableType(new UnionType(new BuiltinType(TypeIdentifier::INT), new BuiltinType(TypeIdentifier::STRING))),
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/TypeInfo/TypeFactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,11 @@ public static function intersection(Type ...$types): IntersectionType
*
* @param T $type
*
* @return ($type is NullableType ? T : NullableType<T>)
* @return T|NullableType<T>
*/
public static function nullable(Type $type): NullableType
public static function nullable(Type $type): Type
{
if ($type instanceof NullableType) {
if ($type->isNullable()) {
return $type;
}

Expand Down

0 comments on commit fc6186c

Please sign in to comment.