Skip to content

Commit

Permalink
Merge pull request #266 from clue-labs/nullable
Browse files Browse the repository at this point in the history
Improve PHP 8.4+ support by avoiding implicitly nullable types
  • Loading branch information
clue authored Nov 22, 2024
2 parents 0e6bdee + 8a57d6d commit 96dd718
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/Io/RouteHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Io/RouteHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 96dd718

Please sign in to comment.