From 11beca762b31722e0e6690446f6dabf83bf9dafa Mon Sep 17 00:00:00 2001 From: Sam Light Date: Wed, 10 Jun 2026 19:00:32 +0100 Subject: code formatting --- src/AbstractStrategy.php | 4 +--- src/Contracts/Strategy.php | 1 + src/Enums/PathSegmentType.php | 6 +++--- src/PathSegmentTypeMatch.php | 3 ++- src/Router.php | 1 + tests/Pest.php | 2 +- tests/Unit/PathSegmentTest.php | 6 +++--- tests/Unit/RouterTest.php | 24 ++++++++++++------------ tests/Utils/TestMiddleware.php | 1 - 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/AbstractStrategy.php b/src/AbstractStrategy.php index 206fd0d..a68f5c1 100644 --- a/src/AbstractStrategy.php +++ b/src/AbstractStrategy.php @@ -35,9 +35,7 @@ abstract class AbstractStrategy implements Strategy { foreach ($parameters as $key => $value) { if (!is_string($value)) { - throw new InvalidArgumentException( - "Parameter {$key} is not a string." - ); + throw new InvalidArgumentException("Parameter {$key} is not a string."); } } diff --git a/src/Contracts/Strategy.php b/src/Contracts/Strategy.php index bf447c3..afd1c8c 100644 --- a/src/Contracts/Strategy.php +++ b/src/Contracts/Strategy.php @@ -26,6 +26,7 @@ interface Strategy /** * @param array $parameters + * * @return array */ public function parseParameters(array $parameters): array; diff --git a/src/Enums/PathSegmentType.php b/src/Enums/PathSegmentType.php index 7cb1a51..414b945 100644 --- a/src/Enums/PathSegmentType.php +++ b/src/Enums/PathSegmentType.php @@ -26,10 +26,10 @@ enum PathSegmentType $regex = $type->routeMatchRegex(); if (preg_match($regex, $value, $matches) === 1) { $value = $matches[1]; - } - else { + } else { $type = PathSegmentType::Raw; } - return new PathSegmentTypeMatch( $type, $value); + + return new PathSegmentTypeMatch($type, $value); } } diff --git a/src/PathSegmentTypeMatch.php b/src/PathSegmentTypeMatch.php index 4e32bdb..c50e74e 100644 --- a/src/PathSegmentTypeMatch.php +++ b/src/PathSegmentTypeMatch.php @@ -9,5 +9,6 @@ readonly class PathSegmentTypeMatch final public function __construct( public PathSegmentType $type, public string $value, - ) {} + ) { + } } diff --git a/src/Router.php b/src/Router.php index 1c5e087..b219651 100644 --- a/src/Router.php +++ b/src/Router.php @@ -181,6 +181,7 @@ class Router { $route = $this->getNamedRoute($name); $params = $this->strategy->parseParameters($params); + return $route?->getPath($params); } } diff --git a/tests/Pest.php b/tests/Pest.php index 9ff7c44..5d7d441 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -2,6 +2,6 @@ use Lightscale\Router\Test\Utils\TestMiddleware; -beforeEach(function() { +beforeEach(function () { TestMiddleware::resetCalls(); }); diff --git a/tests/Unit/PathSegmentTest.php b/tests/Unit/PathSegmentTest.php index ffad95f..5c4788f 100644 --- a/tests/Unit/PathSegmentTest.php +++ b/tests/Unit/PathSegmentTest.php @@ -42,7 +42,7 @@ it('gets key for type :dataset', function (PathSegmentType $type, ?string $res) ($t = PathSegmentType::Parameter)->name => [$t, ''], ]); -it('gets raw keys lowercase', function() { +it('gets raw keys lowercase', function () { $seg = new PathSegment('TesTiNg'); expect($seg->getType())->toBe(PathSegmentType::Raw); expect($seg->getKey())->toBe('testing'); @@ -178,7 +178,7 @@ it('can build full path') ->expect(fn () => $testChain()->getPath()) ->toBe('/test1/test2/test3'); -it('can build path with parameters', function() { +it('can build path with parameters', function () { $seg = new PathSegment(type: PathSegmentType::Root); $child = $seg->child('test1') ->child('test2', PathSegmentType::Parameter) @@ -191,7 +191,7 @@ it('can build path with parameters', function() { ]))->toBe('/test1/a/b/test4'); }); -it('throws when building path with missing parameters', function() { +it('throws when building path with missing parameters', function () { $seg = new PathSegment(type: PathSegmentType::Root); $child = $seg->child('test1') ->child('test2', PathSegmentType::Parameter) diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php index 497772d..9e9de88 100644 --- a/tests/Unit/RouterTest.php +++ b/tests/Unit/RouterTest.php @@ -70,7 +70,7 @@ it('finds segment one falls back to parameter', function () { ->parameters->{'test2'}->toBe('anything'); }); -it('finds segment case insentive', function() { +it('finds segment case insentive', function () { $router = new Router(); $r = $router->root(); @@ -209,9 +209,9 @@ it('make a route', function () { ->toBeInstanceOf(RouteMatch::class); }); -it('make a route with parameter', function() { +it('make a route with parameter', function () { $router = new Router(); - $router->make(HttpMethod::Get, '/test/{test1}/hello', fn() => null); + $router->make(HttpMethod::Get, '/test/{test1}/hello', fn () => null); expect($router->findSegment('/test/hello')) ->not->toBeNull() @@ -281,32 +281,32 @@ it('overrides existing named routes', function () { ->toBe($route2); }); -it('generates route from name', function() { +it('generates route from name', function () { $router = new Router(); - $router->get('/test', fn() => null)->name('test'); + $router->get('/test', fn () => null)->name('test'); expect($router->route('test'))->toBe('/test'); }); -it('generates route with parameters from name', function() { +it('generates route with parameters from name', function () { $router = new Router(); - $router->get('/test/{test1}/hello', fn() => null)->name('test'); + $router->get('/test/{test1}/hello', fn () => null)->name('test'); expect($router->route('test', [ - 'test1' => 'world' + 'test1' => 'world', ]))->toBe('/test/world/hello'); }); -it('throws when generating route with missing parameter from name', function() { +it('throws when generating route with missing parameter from name', function () { $router = new Router(); - $router->get('/test/{test1}/hello', fn() => null)->name('test'); + $router->get('/test/{test1}/hello', fn () => null)->name('test'); $router->route('test', []); })->throws(MissingParameterException::class); -it('throws when generating route with non string parameter from name', function() { +it('throws when generating route with non string parameter from name', function () { $router = new Router(); - $router->get('/test/{test1}/hello', fn() => null)->name('test'); + $router->get('/test/{test1}/hello', fn () => null)->name('test'); $router->route('test', ['test1' => 123]); })->throws(InvalidArgumentException::class); diff --git a/tests/Utils/TestMiddleware.php b/tests/Utils/TestMiddleware.php index 0adb947..eb3ea04 100644 --- a/tests/Utils/TestMiddleware.php +++ b/tests/Utils/TestMiddleware.php @@ -16,7 +16,6 @@ class TestMiddleware implements Middleware private int $call; private int $calls = 0; - public static function resetCalls(): void { self::$staticCalls = 0; -- cgit v1.2.3