-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAstType.php
More file actions
33 lines (26 loc) · 895 Bytes
/
Copy pathAstType.php
File metadata and controls
33 lines (26 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace Bottledcode\DurablePhp\Gateway\Graph;
class AstType
{
public function __construct(public array $types, public bool $nullable) {}
public static function fromArray(array $types): self
{
$isNullable = in_array('null', $types, true);
return new self(array_filter($types, static fn($s) => $s !== 'null'), $isNullable);
}
public function getUnionOrType(): string|Union
{
if (count($this->types) > 1) {
return new Union($this->types);
}
return $this->types[0];
}
public function getUnionOrTypeForInput(): string
{
if (count($this->types) > 1) {
// there simply isn't a way to define an input type that is a union, so we must hope there is a scalar.
return (new Union($this->types))->name . 'Input';
}
return $this->types[0] . 'Input';
}
}