packages/sql-catalog/src/Core/Extension/SinkRole.php
1<?php
2
3declare(strict_types=1);
4
5namespace SqlCatalog\Core\Extension;
6
7/**
8 * What a matched database call does with the statement it is given.
9 *
10 * @visibility root
11 */
12enum SinkRole: string
13{
14 case Query = 'query';
15 case Compose = 'compose';
16 case Prepare = 'prepare';
17 case Execute = 'execute';
18 case Bind = 'bind';
19 case Modelled = 'modelled';
20
21 /**
22 * Whether the call hands the statement text back rather than sending it.
23 *
24 * Some interfaces interpolate a statement and return it for something else
25 * to run. Treating the interpolation as the statement's source, rather than
26 * as a call the analyzer cannot see through, is what keeps the statement
27 * readable where it is finally issued.
28 */
29 public function returnsSql(): bool
30 {
31 return $this === self::Compose;
32 }
33
34 /**
35 * Whether the call carries the statement text itself.
36 */
37 public function carriesSql(): bool
38 {
39 return match ($this) {
40 self::Query, self::Compose, self::Prepare => true,
41 self::Execute, self::Bind, self::Modelled => false,
42 };
43 }
44}
45