Conditions | 1 |
Paths | 1 |
Total Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 6 |
CRAP Score | 1 |
Changes | 0 |
1 | <?php |
||
22 | 84 | public function createSlug(string $input): string |
|
23 | { |
||
24 | // Trim whitespace |
||
25 | 84 | $slug = \trim($input); |
|
26 | // Convert to lowercase |
||
27 | 84 | $slug = \mb_strtolower($slug); |
|
28 | // Try replacing whitespace with a dash |
||
29 | 84 | $slug = \preg_replace('/\s+/u', '-', $slug) ?? $slug; |
|
30 | // Try removing non-alphanumeric and non-dash characters |
||
31 | 84 | $slug = \preg_replace('/[^\p{Lu}\p{Ll}\p{Lt}\p{Nd}\p{Nl}\-]/u', '', $slug) ?? $slug; |
|
32 | |||
33 | 84 | return $slug; |
|
34 | } |
||
35 | } |
||
36 |