Skip to content

Commit a593d72

Browse files
Small refactoring for RouteNameExtender.php
1 parent 842bd87 commit a593d72

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/Extenders/RouteNameExtender.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@
77
use DragonCode\LaravelRouteNames\Routing\Route;
88
use Illuminate\Support\Str;
99

10-
final class RouteNameExtender
10+
class RouteNameExtender
1111
{
1212
public function __invoke(string $name, Route $route): string
1313
{
14-
return Str::of($route->uri())->startsWith('api/v1')
15-
? Str::replaceFirst('api.v1', 'api.v2', $name)
16-
: $name;
14+
return $this->has($route->uri()) ? $this->replace($name) : $name;
15+
}
16+
17+
protected function has(string $uri): bool
18+
{
19+
return Str::of($uri)->startsWith('api/v1');
20+
}
21+
22+
protected function replace(string $name): string
23+
{
24+
return Str::replaceFirst('api.v1', 'api.v2', $name);
1725
}
1826
}

0 commit comments

Comments
 (0)