Skip to content

Commit 8f0ba11

Browse files
committed
TASK: UnionType rename to containsNull, withoutNull
1 parent 5c08a4e commit 8f0ba11

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ public function transpile(TypeReferenceNode $typeReferenceNode): string
5151
default => $this->transpileNonUnionType($type, $typeReferenceNode)
5252
};
5353
}
54-
54+
5555
private function transpileUnionType(UnionType $unionType, TypeReferenceNode $typeReferenceNode): string
5656
{
57-
if ($unionType->isNullable()) {
58-
$nonNullable = $unionType->withoutNullable();
57+
if ($unionType->containsNull()) {
58+
$nonNullable = $unionType->withoutNull();
5959
if ($nonNullable instanceof UnionType) {
6060
throw new \Exception('@TODO Transpilation of nullable union types with more non null members is not implemented');
6161
}
@@ -64,7 +64,7 @@ private function transpileUnionType(UnionType $unionType, TypeReferenceNode $typ
6464

6565
throw new \Exception('@TODO Transpilation of complex union types is not implemented');
6666
}
67-
67+
6868
private function transpileNonUnionType(TypeInterface $type, TypeReferenceNode $typeReferenceNode): string
6969
{
7070
return match ($type::class) {

src/TypeSystem/Resolver/TernaryOperation/TernaryOperationTypeResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ public function resolveTypeOf(TernaryOperationNode $ternaryOperationNode): TypeI
4646
);
4747
$conditionNode = $ternaryOperationNode->condition;
4848

49-
$rootType = $expressionTypeResolver->resolveTypeOf($conditionNode);
49+
$conditionType = $expressionTypeResolver->resolveTypeOf($conditionNode);
5050

5151
if ($conditionNode->root instanceof BooleanLiteralNode) {
5252
return $conditionNode->root->value
5353
? $expressionTypeResolver->resolveTypeOf($ternaryOperationNode->true)
5454
: $expressionTypeResolver->resolveTypeOf($ternaryOperationNode->false);
5555
}
5656

57-
if ($conditionNode->root instanceof IdentifierNode && $rootType instanceof UnionType && $rootType->isNullable()) {
57+
if ($conditionNode->root instanceof IdentifierNode && $conditionType instanceof UnionType && $conditionType->containsNull()) {
5858
$trueExpressionTypeResolver = new ExpressionTypeResolver(
5959
scope: new ShallowScope(
6060
$conditionNode->root->value,
61-
$rootType->withoutNullable(),
61+
$conditionType->withoutNull(),
6262
$this->scope
6363
)
6464
);

src/TypeSystem/Type/UnionType/UnionType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function of(TypeInterface ...$members): TypeInterface
6363
return new self(...$uniqueMembers);
6464
}
6565

66-
public function isNullable(): bool
66+
public function containsNull(): bool
6767
{
6868
foreach ($this->members as $member) {
6969
if ($member->is(NullType::get())) {
@@ -73,7 +73,7 @@ public function isNullable(): bool
7373
return false;
7474
}
7575

76-
public function withoutNullable(): TypeInterface
76+
public function withoutNull(): TypeInterface
7777
{
7878
$nonNullMembers = [];
7979
foreach ($this->members as $member) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public function isNullableOnNullableString(): void
129129

130130
$this->assertInstanceOf(UnionType::class, $unionType);
131131

132-
$this->assertTrue($unionType->isNullable());
132+
$this->assertTrue($unionType->containsNull());
133133

134-
$nonNullables = $unionType->withoutNullable();
134+
$nonNullables = $unionType->withoutNull();
135135

136136
$this->assertTrue($nonNullables->is(StringType::get()));
137137
}
@@ -145,9 +145,9 @@ public function isNullableWithMultipleItems(): void
145145

146146
$this->assertInstanceOf(UnionType::class, $unionType);
147147

148-
$this->assertTrue($unionType->isNullable());
148+
$this->assertTrue($unionType->containsNull());
149149

150-
$nonNullables = $unionType->withoutNullable();
150+
$nonNullables = $unionType->withoutNull();
151151

152152
$this->assertTrue($nonNullables->is(UnionType::of(StringType::get(), NumberType::get())));
153153
}
@@ -161,9 +161,9 @@ public function isNullableOnNonNullableUnion(): void
161161

162162
$this->assertInstanceOf(UnionType::class, $unionType);
163163

164-
$this->assertFalse($unionType->isNullable());
164+
$this->assertFalse($unionType->containsNull());
165165

166-
$nonNullables = $unionType->withoutNullable();
166+
$nonNullables = $unionType->withoutNull();
167167

168168
$this->assertTrue($nonNullables->is($unionType));
169169
}

0 commit comments

Comments
 (0)