summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Light <sam@lightscale.co.uk>2026-06-10 19:00:32 +0100
committerSam Light <sam@lightscale.co.uk>2026-06-10 19:00:32 +0100
commit7a19b83bf7d7d8a2650356168cdb296b6f82807f (patch)
tree81891e5791d18daa8ec34497131fb65615039858
parent8c0efd0d9317ad92bd55cd6afcd41bdbab827bf8 (diff)
code formatting
-rw-r--r--src/Contracts/Strategy.php1
-rw-r--r--src/RouteCall.php3
-rw-r--r--src/Router.php8
-rw-r--r--tests/Unit/BasicStrategyTest.php12
-rw-r--r--tests/Unit/PathSegmentMatchTest.php2
-rw-r--r--tests/Unit/RouteCallTest.php2
-rw-r--r--tests/Unit/RouteTest.php3
-rw-r--r--tests/Unit/RouterTest.php14
-rw-r--r--tests/Utils/TestCall.php3
-rw-r--r--tests/Utils/TestCallable.php1
10 files changed, 24 insertions, 25 deletions
diff --git a/src/Contracts/Strategy.php b/src/Contracts/Strategy.php
index 81d6ec3..bb877c1 100644
--- a/src/Contracts/Strategy.php
+++ b/src/Contracts/Strategy.php
@@ -11,5 +11,6 @@ use Psr\Http\Message\ResponseInterface;
interface Strategy
{
public function runRoute(RouteCall $call): ResponseInterface;
+
public function notFound(RequestInterface $request): ResponseInterface;
}
diff --git a/src/RouteCall.php b/src/RouteCall.php
index b76a780..c598748 100644
--- a/src/RouteCall.php
+++ b/src/RouteCall.php
@@ -13,5 +13,6 @@ class RouteCall
public RequestInterface $request,
public Route $route,
public array $parameters,
- ) {}
+ ) {
+ }
}
diff --git a/src/Router.php b/src/Router.php
index ddd3220..87f7931 100644
--- a/src/Router.php
+++ b/src/Router.php
@@ -7,8 +7,6 @@ namespace Lightscale\Router;
use Lightscale\Router\Contracts\Strategy;
use Lightscale\Router\Enums\HttpMethod;
use Lightscale\Router\Enums\PathSegmentType;
-use Lightscale\Router\Exceptions\NotFoundException;
-use Lightscale\Router\Exceptions\UnknownMethodException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
@@ -20,7 +18,7 @@ class Router
public function __construct()
{
$this->root = new PathSegment(type: PathSegmentType::Root);
- $this->strategy = new BasicStrategy;
+ $this->strategy = new BasicStrategy();
}
public function getStrategy(): Strategy
@@ -80,7 +78,7 @@ class Router
$method = $request->getMethod();
$method = HttpMethod::tryFrom(strtolower($method));
- if ($method === null) {
+ if (null === $method) {
return $this->strategy->notFound($request);
}
@@ -104,7 +102,7 @@ class Router
$pathSplit = $this->splitPath($path);
$seg = $this->root();
- while(($v = array_shift($pathSplit)) !== null) {
+ while (($v = array_shift($pathSplit)) !== null) {
$seg = $seg->child($v);
}
diff --git a/tests/Unit/BasicStrategyTest.php b/tests/Unit/BasicStrategyTest.php
index 2a0b550..1f1489a 100644
--- a/tests/Unit/BasicStrategyTest.php
+++ b/tests/Unit/BasicStrategyTest.php
@@ -9,12 +9,12 @@ use Lightscale\Router\Test\Utils\TestCallable;
use Nyholm\Psr7\Factory\Psr17Factory;
it('initialises')
- ->expect(fn() => new BasicStrategy)
+ ->expect(fn () => new BasicStrategy())
->toBeInstanceOf(BasicStrategy::class);
-it('throws on not found', function() {
- (new BasicStrategy)->notFound(
- (new Psr17Factory)->createServerRequest(
+it('throws on not found', function () {
+ (new BasicStrategy())->notFound(
+ (new Psr17Factory())->createServerRequest(
HttpMethod::Get->value,
'/testing/testing'
)
@@ -22,10 +22,10 @@ it('throws on not found', function() {
})->throws(NotFoundException::class);
it('calls route', function () {
- $factory = new Psr17Factory;
+ $factory = new Psr17Factory();
$response = $factory->createResponse(200, 'OK');
$cb = TestCallable::make(fn () => $response);
- $res = (new BasicStrategy)->runRoute($rc = new RouteCall(
+ $res = (new BasicStrategy())->runRoute($rc = new RouteCall(
$factory->createServerRequest(
HttpMethod::Get->value,
'/testing/testing'
diff --git a/tests/Unit/PathSegmentMatchTest.php b/tests/Unit/PathSegmentMatchTest.php
index 9a522a4..3059f26 100644
--- a/tests/Unit/PathSegmentMatchTest.php
+++ b/tests/Unit/PathSegmentMatchTest.php
@@ -5,7 +5,7 @@ declare(strict_types=1);
use Lightscale\Router\PathSegment;
use Lightscale\Router\PathSegmentMatch;
-it('initializes with segment and params', function() {
+it('initializes with segment and params', function () {
$match = new PathSegmentMatch(
$seg = new PathSegment('testing'),
$params = ['test1' => 'test2'],
diff --git a/tests/Unit/RouteCallTest.php b/tests/Unit/RouteCallTest.php
index 70cc50e..ece0b91 100644
--- a/tests/Unit/RouteCallTest.php
+++ b/tests/Unit/RouteCallTest.php
@@ -8,7 +8,7 @@ use Lightscale\Router\RouteCall;
use Nyholm\Psr7\Factory\Psr17Factory;
it('initializes with data', function () {
- $factory = new Psr17Factory;
+ $factory = new Psr17Factory();
$call = new RouteCall(
request: $req = $factory->createServerRequest(HttpMethod::Get->value, '/test/test'),
route: $route = new Route(HttpMethod::Get, fn () => null),
diff --git a/tests/Unit/RouteTest.php b/tests/Unit/RouteTest.php
index 50513a1..e4ce06d 100644
--- a/tests/Unit/RouteTest.php
+++ b/tests/Unit/RouteTest.php
@@ -6,7 +6,6 @@ use Lightscale\Router\Enums\HttpMethod;
use Lightscale\Router\Enums\PathSegmentType;
use Lightscale\Router\PathSegment;
use Lightscale\Router\Route;
-use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Http\Message\RequestInterface;
it('initializes')
@@ -47,7 +46,7 @@ it('gets method')
))->getMethod())
->toBe(HttpMethod::Get);
-it('can get handler', function() {
+it('can get handler', function () {
$r = new Route(
HttpMethod::Get,
$h = fn (RequestInterface $req) => $req->getUri()->getPath()
diff --git a/tests/Unit/RouterTest.php b/tests/Unit/RouterTest.php
index 12e27a4..421cc7c 100644
--- a/tests/Unit/RouterTest.php
+++ b/tests/Unit/RouterTest.php
@@ -17,12 +17,12 @@ it('initializes')
->toBeInstanceOf(Router::class);
it('initializes with basic strategy')
- ->expect((new Router)->getStrategy())
+ ->expect((new Router())->getStrategy())
->toBeInstanceOf(BasicStrategy::class);
-it('can set strategy', function() {
- $router = new Router;
- $s = new BasicStrategy;
+it('can set strategy', function () {
+ $router = new Router();
+ $s = new BasicStrategy();
expect($router->getStrategy())->not->toBe($s);
$router->setStrategy($s);
expect($router->getStrategy())->toBe($s);
@@ -109,7 +109,7 @@ it('return null when segment not found', function () {
it('calls strategy notFound with dispatch', function () {
$router = new Router();
- $factory = new Psr17Factory;
+ $factory = new Psr17Factory();
$request = $factory->createServerRequest(HttpMethod::Get->value, '/testing/testing');
$response = $factory->createResponse();
@@ -123,7 +123,7 @@ it('calls strategy notFound with dispatch', function () {
expect($result)->toBe($response);
});
-it('calls strategy runRoute with dispatch on match', function() {
+it('calls strategy runRoute with dispatch on match', function () {
$router = new Router();
$router->root()->child('testing')->addRoute(new Route(
@@ -131,7 +131,7 @@ it('calls strategy runRoute with dispatch on match', function() {
fn () => null,
));
- $factory = new Psr17Factory;
+ $factory = new Psr17Factory();
$request = $factory->createServerRequest(HttpMethod::Get->value, '/testing');
$response = $factory->createResponse();
diff --git a/tests/Utils/TestCall.php b/tests/Utils/TestCall.php
index 971e6a7..3b9a2f3 100644
--- a/tests/Utils/TestCall.php
+++ b/tests/Utils/TestCall.php
@@ -12,5 +12,6 @@ readonly class TestCall
public function __construct(
public array $args,
public mixed $return,
- ){}
+ ) {
+ }
}
diff --git a/tests/Utils/TestCallable.php b/tests/Utils/TestCallable.php
index 42a3bb5..526ddf4 100644
--- a/tests/Utils/TestCallable.php
+++ b/tests/Utils/TestCallable.php
@@ -65,5 +65,4 @@ class TestCallable
{
Assert::assertSame($amount, $this->getCallCount());
}
-
}