| Total Complexity | 6 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 94.74% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 5 | class Spinner |
||
| 6 | { |
||
| 7 | 3 | public static function spin(string $text): string |
|
| 8 | { |
||
| 9 | 3 | if (! preg_match('/\{(.*)\}/si', $text)) { |
|
| 10 | 3 | return self::removeExtraSpaces($text); |
|
| 11 | } else { |
||
| 12 | 3 | preg_match_all('/\{([^{}]*)\}/si', $text, $matches); |
|
| 13 | 3 | $occur = count($matches[1]); |
|
| 14 | 3 | for ($i = 0; $i < $occur; ++$i) { |
|
| 15 | 3 | $words = explode('|', $matches[1][$i]); |
|
| 16 | 3 | shuffle($words); |
|
| 17 | 3 | $text = self::replaceOnce($matches[0][$i], $words[0], $text); |
|
| 18 | } |
||
| 19 | |||
| 20 | 3 | return self::spin($text); |
|
| 21 | } |
||
| 22 | } |
||
| 23 | |||
| 24 | 3 | protected static function replaceOnce(string $search, string $replace, string $subject): string |
|
| 34 | } |
||
| 35 | } |
||
| 36 | |||
| 37 | 3 | protected static function removeExtraSpaces(string $text): string |
|
| 40 | } |
||
| 41 | } |
||
| 42 |