| Total Complexity | 5 |
| Total Lines | 31 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | class CleanupUuidOrName |
||
| 10 | { |
||
| 11 | public function handle(Request $request, \Closure $next): mixed |
||
| 12 | { |
||
| 13 | /** @var array $route */ |
||
| 14 | $route = $request->route(); |
||
| 15 | if (isset($route[2]['uuid'])) { |
||
| 16 | $route[2]['uuid'] = $this->cleanUuid($route[2]['uuid']); |
||
| 17 | } |
||
| 18 | |||
| 19 | if (isset($route[2]['username'])) { |
||
| 20 | $route[2]['username'] = $this->cleanUsername($route[2]['username']); |
||
| 21 | } |
||
| 22 | |||
| 23 | $request->setRouteResolver(static function () use ($route) { |
||
| 24 | return $route; |
||
| 25 | }); |
||
| 26 | |||
| 27 | return $next($request); |
||
| 28 | } |
||
| 29 | |||
| 30 | private function cleanUuid(string $uuid): string |
||
| 31 | { |
||
| 32 | $uuid = (string) preg_replace("#\.png.*#", '', $uuid); |
||
| 33 | |||
| 34 | return str_replace('-', '', $uuid); |
||
| 35 | } |
||
| 36 | |||
| 37 | private function cleanUsername(string $username): string |
||
| 40 | } |
||
| 41 | } |
||
| 42 |