From 8a57d6dfb287508f626870df7aa3329659ecfefe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Tue, 19 Mar 2024 15:33:26 +0100 Subject: [PATCH] Improve PHP 8.4+ support by avoiding implicitly nullable types --- composer.json | 10 +++++----- src/Container.php | 4 ++-- src/Io/RouteHandler.php | 2 +- tests/ContainerTest.php | 4 ++-- tests/Io/RouteHandlerTest.php | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 5e1f56e..d444a4d 100644 --- a/composer.json +++ b/composer.json @@ -13,16 +13,16 @@ "require": { "php": ">=7.1", "nikic/fast-route": "^1.3", - "react/async": "^4 || ^3", - "react/http": "^1.10", - "react/promise": "^3", - "react/socket": "^1.14" + "react/async": "^4.3 || ^3", + "react/http": "^1.11", + "react/promise": "^3.2", + "react/socket": "^1.15" }, "require-dev": { "phpstan/phpstan": "1.10.47 || 1.4.10", "phpunit/phpunit": "^9.6 || ^7.5", "psr/container": "^2 || ^1", - "react/promise-timer": "^1.10" + "react/promise-timer": "^1.11" }, "autoload": { "psr-4": { diff --git a/src/Container.php b/src/Container.php index 2058379..42dd1d3 100644 --- a/src/Container.php +++ b/src/Container.php @@ -41,7 +41,7 @@ public function __construct($loader = []) } /** @return mixed */ - public function __invoke(ServerRequestInterface $request, callable $next = null) + public function __invoke(ServerRequestInterface $request, ?callable $next = null) { if ($next === null) { // You don't want to end up here. This only happens if you use the @@ -64,7 +64,7 @@ public function __invoke(ServerRequestInterface $request, callable $next = null) */ public function callable(string $class): callable { - return function (ServerRequestInterface $request, callable $next = null) use ($class) { + return function (ServerRequestInterface $request, ?callable $next = null) use ($class) { // Check `$class` references a valid class name that can be autoloaded if (\is_array($this->container) && !\class_exists($class, true) && !interface_exists($class, false) && !trait_exists($class, false)) { throw new \BadMethodCallException('Request handler class ' . $class . ' not found'); diff --git a/src/Io/RouteHandler.php b/src/Io/RouteHandler.php index 2b0cf1c..2bd988b 100644 --- a/src/Io/RouteHandler.php +++ b/src/Io/RouteHandler.php @@ -30,7 +30,7 @@ class RouteHandler /** @var Container */ private $container; - public function __construct(Container $container = null) + public function __construct(?Container $container = null) { $this->routeCollector = new RouteCollector(new RouteParser(), new RouteGenerator()); $this->errorHandler = new ErrorHandler(); diff --git a/tests/ContainerTest.php b/tests/ContainerTest.php index fcff810..93829d7 100644 --- a/tests/ContainerTest.php +++ b/tests/ContainerTest.php @@ -169,7 +169,7 @@ public function testCallableReturnsCallableForClassWithNullDefaultViaAutowiringW /** @var \stdClass|null|false */ private $data = false; - public function __construct(\stdClass $data = null) + public function __construct(?\stdClass $data = null) { $this->data = $data; } @@ -199,7 +199,7 @@ public function testCallableReturnsCallableForClassWithNullDefaultViaContainerCo /** @var \stdClass|null|false */ private $data = false; - public function __construct(\stdClass $data = null) + public function __construct(?\stdClass $data = null) { $this->data = $data; } diff --git a/tests/Io/RouteHandlerTest.php b/tests/Io/RouteHandlerTest.php index abf4482..e76b3a9 100644 --- a/tests/Io/RouteHandlerTest.php +++ b/tests/Io/RouteHandlerTest.php @@ -205,7 +205,7 @@ public function testHandleRequestWithGetRequestReturnsResponseFromMatchingHandle $controller = new class { /** @var ?Response */ public static $response; - public function __construct(int $value = null) + public function __construct(?int $value = null) { assert($value === null); }