Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
TextUtils | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
replaceBlanks | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
2 | |||
arrayExport | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace San\Crud\Utils; |
4 | |
5 | use Illuminate\Support\Str; |
6 | |
7 | class TextUtils { |
8 | public static function replaceBlanks(string $text, array $replacements = []) { |
9 | foreach ($replacements as $key => $value) { |
10 | $k = "_{$key}_"; |
11 | $text = str_replace("/*\$$k*/", "\$$value", $text); |
12 | $text = str_replace("/*$k*/", $value, $text); |
13 | $text = str_replace($k, $value, $text); |
14 | } |
15 | |
16 | return preg_replace('/(\s*\n){2,}/', "\n\n", $text); |
17 | } |
18 | |
19 | public static function arrayExport($arr) { |
20 | return sprintf('[%s]', implode(', ', array_map(fn($v) => is_string($v) ? sprintf('"%s" => "%s"', $v, Str::title($v)) : $v, $arr))); |
21 | } |
22 | } |