Lines 100.00% 3 / 3
Functions and Methods 100.00% 1 / 1
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ColumnType 100.00% 3 / 3 100.00% 1 / 1 3 100.00% 1 / 1
 primaryKeyCapable 100.00% 3 / 3 100.00% 1 / 1 3
1<?php
2
3declare(strict_types=1);
4
5namespace BlueprintAU\Radiant\Database\Schema\Enums;
6
7/**
8 * The logical column types understood by the schema layer.
9 */
10enum ColumnType: string
11{
12    /** A variable-length string (requires a length). */
13    case String = 'string';
14
15    /** A fixed-length string (requires a length) — ISO codes, padded identifiers. */
16    case Char = 'char';
17
18    /** An unbounded text column. */
19    case Text = 'text';
20
21    /** A 64-bit integer. */
22    case BigInt = 'bigint';
23
24    /** A 32-bit integer. */
25    case Int = 'int';
26
27    /** An exact fixed-point number — `precision` total digits, `scale` fractional digits. */
28    case Decimal = 'decimal';
29
30    /** A floating-point number. */
31    case Float = 'float';
32
33    /** A boolean. */
34    case Boolean = 'boolean';
35
36    /** A calendar date (no time component). */
37    case Date = 'date';
38
39    /** A date-time value. */
40    case DateTime = 'datetime';
41
42    /** A Unix timestamp. */
43    case Timestamp = 'timestamp';
44
45    /** A JSON document. */
46    case Json = 'json';
47
48    /** A constrained string — rendered as a sized string plus an inline CHECK over `values`. */
49    case Enum = 'enum';
50
51    /** Raw binary bytes. */
52    case Binary = 'binary';
53
54    /** A RFC 4122 UUID (fixed 36 characters). */
55    case Uuid = 'uuid';
56
57    /**
58     * Whether this type can hold a primary-key (or morph-key) value.
59     *
60     * @return bool
61     */
62    public function primaryKeyCapable(): bool
63    {
64        return match ($this) {
65            ColumnType::BigInt, ColumnType::Int, ColumnType::String, ColumnType::Char, ColumnType::Uuid => true,
66            default => false,
67        };
68    }
69}