Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
Sql | |
100.00% |
9 / 9 |
|
100.00% |
6 / 6 |
7 | |
100.00% |
1 / 1 |
quoteList | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
quote | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
quoteAndJoin | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
splitThenQuoteAndJoin | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
splitAndQuote | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
splitAndQuoteThenJoin | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace Projom\Util; |
6 | |
7 | use Projom\Util\Arrays; |
8 | use Projom\Util\Strings; |
9 | |
10 | class Sql |
11 | { |
12 | public static function quoteList(array $list): array |
13 | { |
14 | return array_map([static::class, 'quote'], $list); |
15 | } |
16 | |
17 | public static function quote(string $subject): string |
18 | { |
19 | $subject = Strings::clean($subject); |
20 | |
21 | if ($subject === '*') |
22 | return $subject; |
23 | |
24 | return "`$subject`"; |
25 | } |
26 | |
27 | public static function quoteAndJoin(array $list, string $delimeter = ','): string |
28 | { |
29 | return Arrays::join(static::quoteList($list), $delimeter); |
30 | } |
31 | |
32 | public static function splitThenQuoteAndJoin(string $subject, string $delimeter = ','): string |
33 | { |
34 | return static::quoteAndJoin(Strings::split($subject, $delimeter), $delimeter); |
35 | } |
36 | |
37 | public static function splitAndQuote(string $subject, string $delimeter = ','): array |
38 | { |
39 | return static::quoteList(Strings::split($subject, $delimeter)); |
40 | } |
41 | |
42 | public static function splitAndQuoteThenJoin(string $subject, string $delimeter = ','): string |
43 | { |
44 | return Arrays::join(static::splitAndQuote($subject, $delimeter), $delimeter); |
45 | } |
46 | } |