Total Complexity | 4 |
Total Lines | 27 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | class Utils |
||
15 | { |
||
16 | public static function nowdoc(string $str) : string |
||
17 | { |
||
18 | $lines = preg_split('/\\n/', $str); |
||
19 | |||
20 | if ($lines === false) { |
||
21 | return ''; |
||
22 | } |
||
23 | |||
24 | if (count($lines) <= 2) { |
||
25 | return ''; |
||
26 | } |
||
27 | |||
28 | // Toss out the first and last lines. |
||
29 | $lines = array_slice($lines, 1, count($lines) - 2); |
||
30 | |||
31 | // take the tabs from the first line, and subtract them from all lines |
||
32 | $matches = []; |
||
33 | preg_match('/(^[ \t]+)/', $lines[0], $matches); |
||
34 | |||
35 | $numLines = count($lines); |
||
36 | for ($i = 0; $i < $numLines; $i++) { |
||
37 | $lines[$i] = str_replace($matches[0], '', $lines[$i]); |
||
38 | } |
||
39 | |||
40 | return implode("\n", $lines); |
||
41 | } |
||
43 |