Lines
100.00%
1 / 1
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Unique | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace BlueprintAU\Radiant\Attributes; | |
| 6 | ||
| 7 | /** | |
| 8 | * Declares a UNIQUE constraint over one or more columns (class-level). | |
| 9 | * | |
| 10 | * Single-column convenience stays on {@see Column}'s `unique` flag; use this | |
| 11 | * attribute for composite constraints — or any constraint needing a custom | |
| 12 | * configuration the flag cannot express. One mental rule: **a constraint | |
| 13 | * over more than one column — or one needing explicit configuration — is a | |
| 14 | * class-level attribute.** | |
| 15 | * | |
| 16 | * Column names are strings (PHP attributes cannot reference other | |
| 17 | * properties); the {@see \BlueprintAU\Radiant\Metadata\MetadataFactory} validates every name against the | |
| 18 | * model's `#[Column]` set at build time, so a renamed property fails loudly | |
| 19 | * at build, not as a broken constraint in the database. | |
| 20 | * | |
| 21 | * A flag and an attribute covering the same single column is a duplicate | |
| 22 | * declaration and fails fast at build — the two mechanisms can never | |
| 23 | * silently double-declare. | |
| 24 | */ | |
| 25 | #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] | |
| 26 | final class Unique | |
| 27 | { | |
| 28 | /** | |
| 29 | * Create a unique-constraint declaration. | |
| 30 | * | |
| 31 | * @param list<string> $columns | |
| 32 | * @param string|null $name | |
| 33 | * @param string|null $where | |
| 34 | * @param bool $nullsNotDistinct | |
| 35 | */ | |
| 36 | public function __construct( | |
| 37 | public array $columns, | |
| 38 | public string|null $name = null, | |
| 39 | public string|null $where = null, | |
| 40 | public bool $nullsNotDistinct = false, | |
| 41 | ) { | |
| 42 | } | |
| 43 | } |