packages/sql-semantics-sqlite/src/Model/Statement/Shape/DependentField.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlSemantics\Platform\Sqlite\Model\Statement\Shape;
6
7use SqlSemantics\Platform\Sqlite\Model\Diagnostic\Check;
8use SqlSemantics\Platform\Sqlite\Model\Statement\Reference\Missing\MissingInput;
9use SqlSemantics\Platform\Sqlite\Model\Statement\Snapshot;
10
11/**
12 * A field lookup that missing declarations leave undecided.
13 *
14 * The known fields with the name are candidates; an unexpanded star may add
15 * further fields with that name, so no candidate is chosen.
16 *
17 * @visibility public
18 * @example Looking a name up in an open shape
19 * $operation = (new \SqlSemantics\Platform\Sqlite\Semantics())->analyze('SELECT * FROM t');
20 * $operation->lookupField('a') instanceof \SqlSemantics\Platform\Sqlite\Model\Statement\Shape\DependentField // => true
21 */
22final class DependentField implements FieldLookup
23{
24 use Snapshot;
25
26 /**
27 * @var list<Field> The known fields with the name
28 */
29 public readonly array $candidates;
30
31 /**
32 * @var non-empty-list<MissingInput> The inputs needed to decide the lookup
33 */
34 public readonly array $missing;
35
36 /**
37 * @param string $name The looked-up name
38 * @param list<Field> $candidates The known fields with the name
39 * @param list<MissingInput> $missing The inputs needed to decide the lookup; at least one
40 */
41 public function __construct(public readonly string $name, array $candidates, array $missing)
42 {
43 $this->candidates = Check::listOf($candidates, Field::class, 'A dependent lookup holds candidate fields.');
44 $this->missing = Check::listOf($missing, MissingInput::class, 'A dependent lookup names its missing inputs.', 1);
45 }
46}
47