| Conditions | 1 |
| Paths | 1 |
| Total Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 6 |
| CRAP Score | 1 |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | 177 | public function normalize(string $text, $context = null): string |
|
| 25 | { |
||
| 26 | // Trim whitespace |
||
| 27 | 177 | $slug = \trim($text); |
|
| 28 | // Convert to lowercase |
||
| 29 | 177 | $slug = \mb_strtolower($slug); |
|
| 30 | // Try replacing whitespace with a dash |
||
| 31 | 177 | $slug = \preg_replace('/\s+/u', '-', $slug) ?? $slug; |
|
| 32 | // Try removing characters other than letters, numbers, and marks. |
||
| 33 | 177 | $slug = \preg_replace('/[^\p{L}\p{Nd}\p{Nl}\p{M}-]+/u', '', $slug) ?? $slug; |
|
| 34 | |||
| 35 | 177 | return $slug; |
|
| 36 | } |
||
| 37 | } |
||
| 38 |