Skip to content

Commit 492e05c

Browse files
committed
TASK: Adjust naming of $nonNullable to $typeWithoutNull
1 parent 1348ac1 commit 492e05c

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

src/Target/Php/Transpiler/TypeReference/TypeReferenceTranspiler.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,9 @@ public function transpile(TypeReferenceNode $typeReferenceNode): string
5454

5555
private function transpileUnionType(UnionType $unionType, TypeReferenceNode $typeReferenceNode): string
5656
{
57-
if ($unionType->containsNull()) {
58-
$nonNullable = $unionType->withoutNull();
59-
if ($nonNullable instanceof UnionType) {
60-
throw new \Exception('@TODO Transpilation of nullable union types with more non null members is not implemented');
61-
}
62-
return $this->transpileNullableType($nonNullable, $typeReferenceNode);
57+
if (count($unionType) === 2 && $unionType->containsNull()) {
58+
$typeWithoutNull = $unionType->withoutNull();
59+
return $this->transpileNullableType($typeWithoutNull, $typeReferenceNode);
6360
}
6461

6562
throw new \Exception('@TODO Transpilation of complex union types is not implemented');

test/Unit/TypeSystem/Type/UnionType/UnionTypeTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,48 +133,48 @@ public function isReturnsFalseIfGivenTypeIsNotCongruent(): void
133133
/**
134134
* @test
135135
*/
136-
public function isNullableOnNullableString(): void
136+
public function containsNullOnNullableString(): void
137137
{
138138
$unionType = UnionType::of(StringType::get(), NullType::get());
139139

140140
$this->assertInstanceOf(UnionType::class, $unionType);
141141

142142
$this->assertTrue($unionType->containsNull());
143143

144-
$nonNullables = $unionType->withoutNull();
144+
$withoutNull = $unionType->withoutNull();
145145

146-
$this->assertTrue($nonNullables->is(StringType::get()));
146+
$this->assertTrue($withoutNull->is(StringType::get()));
147147
}
148148

149149
/**
150150
* @test
151151
*/
152-
public function isNullableWithMultipleItems(): void
152+
public function containsNullWithMultipleMembers(): void
153153
{
154154
$unionType = UnionType::of(StringType::get(), NumberType::get(), NullType::get());
155155

156156
$this->assertInstanceOf(UnionType::class, $unionType);
157157

158158
$this->assertTrue($unionType->containsNull());
159159

160-
$nonNullables = $unionType->withoutNull();
160+
$withoutNull = $unionType->withoutNull();
161161

162-
$this->assertTrue($nonNullables->is(UnionType::of(StringType::get(), NumberType::get())));
162+
$this->assertTrue($withoutNull->is(UnionType::of(StringType::get(), NumberType::get())));
163163
}
164164

165165
/**
166166
* @test
167167
*/
168-
public function isNullableOnNonNullableUnion(): void
168+
public function withoutNullOnUnionWithoutNull(): void
169169
{
170170
$unionType = UnionType::of(StringType::get(), NumberType::get());
171171

172172
$this->assertInstanceOf(UnionType::class, $unionType);
173173

174174
$this->assertFalse($unionType->containsNull());
175175

176-
$nonNullables = $unionType->withoutNull();
176+
$withoutNull = $unionType->withoutNull();
177177

178-
$this->assertTrue($nonNullables->is($unionType));
178+
$this->assertTrue($withoutNull->is($unionType));
179179
}
180180
}

0 commit comments

Comments
 (0)