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 | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ConcatenatesStatements | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | 100.00% | 1 / 1 | |||
| concatenate | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace BlueprintAU\Radiant\Database\Concerns; | |
| 6 | ||
| 7 | /** | |
| 8 | * Statement-assembly helpers shared by the query and schema grammars. | |
| 9 | * | |
| 10 | * The same rule both grammars follow: a statement is OPTIONAL segments | |
| 11 | * (clauses that may not apply), joined by {@see ConcatenatesStatements::concatenate()}; | |
| 12 | * a LIST is non-optional items (columns, orders), joined by plain `implode`. | |
| 13 | * Silently filtering list items hides a bug; silently filtering absent | |
| 14 | * clauses is the job. | |
| 15 | */ | |
| 16 | trait ConcatenatesStatements | |
| 17 | { | |
| 18 | /** | |
| 19 | * Join statement segments with a single space, dropping empty ones. | |
| 20 | * | |
| 21 | * Do NOT use this to join list items (columns, orders, bindings) — those | |
| 22 | * are non-optional and joined with plain `implode`. | |
| 23 | * | |
| 24 | * @param list<string> $segments | |
| 25 | * @return string | |
| 26 | */ | |
| 27 | protected function concatenate(array $segments): string | |
| 28 | { | |
| 29 | return implode(' ', array_filter($segments, fn ($segment) => $segment !== '')); | |
| 30 | } | |
| 31 | } |