Lines
100.00%
6 / 6
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| derive | 100.00% | 6 / 6 | 100.00% | 1 / 1 | 5 | ||
| 10 | final class ConstraintNamer | |
| 11 | { | |
| 12 | /** | |
| 13 | * Derive a constraint name: `{table}_{columns}_{suffix}`. | |
| 14 | * | |
| 15 | * @param string $table | |
| 16 | * @param list<string> $columns | |
| 17 | * @param string $suffix | |
| 18 | * @return string | |
| 19 | * @throws \InvalidArgumentException | |
| 20 | */ | |
| 21 | public static function derive(string $table, array $columns, string $suffix): string | |
| 22 | { | |
| 23 | if ($table === '' || $suffix === '' || $columns === [] || in_array('', $columns, true)) { | |
| 24 | throw new \InvalidArgumentException( | |
| 25 | 'A derived constraint name requires a non-empty table, suffix, and columns; got ' | |
| 26 | . "table [{$table}], suffix [{$suffix}], columns [" . implode(', ', $columns) . '].' | |
| 27 | ); | |
| 28 | } | |
| 29 | ||
| 30 | return implode('_', [$table, ...$columns, $suffix]); | |
| 31 | } | |
| 32 | } |