Skip to content

Commit

Permalink
[3.x] Improve PHP 8.4+ support by avoiding implicitly nullable types
Browse files Browse the repository at this point in the history
This changeset improves PHP 8.4+ support by avoiding implicitly nullable types as discussed in reactphp/promise#260.

I'm planning to add native types to the public API and introduce PHPStan in follow-up PRs.

Once merged, we should apply similar changes to all our upcoming v3 components. On top of this, we should backport similar changes to the v1 branch.

Builds on top of #182, #222 and reactphp/promise#260
  • Loading branch information
WyriHaximus committed Jun 5, 2024
1 parent d9681b1 commit c15a0d6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
"php": ">=7.1",
"react/cache": "^1.0 || ^0.6 || ^0.5",
"react/event-loop": "^1.2",
"react/promise": "^3.0 || ^2.7 || ^1.2.1"
"react/promise": "^3.2 || ^2.7 || ^1.2.1"
},
"require-dev": {
"phpunit/phpunit": "^9.6 || ^7.5",
"react/async": "^4 || ^3 || ^2",
"react/promise-timer": "^1.9"
"react/async": "^4.3 || ^3 || ^2",
"react/promise-timer": "^1.11"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Query/TcpTransportExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class TcpTransportExecutor implements ExecutorInterface
* @param string $nameserver
* @param ?LoopInterface $loop
*/
public function __construct($nameserver, LoopInterface $loop = null)
public function __construct($nameserver, ?LoopInterface $loop = null)
{
if (\strpos($nameserver, '[') === false && \substr_count($nameserver, ':') >= 2 && \strpos($nameserver, '://') === false) {
// several colons, but not enclosed in square brackets => enclose IPv6 address in square brackets
Expand Down
2 changes: 1 addition & 1 deletion src/Query/TimeoutExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class TimeoutExecutor implements ExecutorInterface
private $loop;
private $timeout;

public function __construct(ExecutorInterface $executor, $timeout, LoopInterface $loop = null)
public function __construct(ExecutorInterface $executor, $timeout, ?LoopInterface $loop = null)
{
$this->executor = $executor;
$this->loop = $loop ?: Loop::get();
Expand Down
2 changes: 1 addition & 1 deletion src/Query/UdpTransportExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ final class UdpTransportExecutor implements ExecutorInterface
* @param string $nameserver
* @param ?LoopInterface $loop
*/
public function __construct($nameserver, LoopInterface $loop = null)
public function __construct($nameserver, ?LoopInterface $loop = null)
{
if (\strpos($nameserver, '[') === false && \substr_count($nameserver, ':') >= 2 && \strpos($nameserver, '://') === false) {
// several colons, but not enclosed in square brackets => enclose IPv6 address in square brackets
Expand Down
4 changes: 2 additions & 2 deletions src/Resolver/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class Factory
* @throws \InvalidArgumentException for invalid DNS server address
* @throws \UnderflowException when given DNS Config object has an empty list of nameservers
*/
public function create($config, LoopInterface $loop = null)
public function create($config, ?LoopInterface $loop = null)
{
$executor = $this->decorateHostsFileExecutor($this->createExecutor($config, $loop ?: Loop::get()));

Expand All @@ -59,7 +59,7 @@ public function create($config, LoopInterface $loop = null)
* @throws \InvalidArgumentException for invalid DNS server address
* @throws \UnderflowException when given DNS Config object has an empty list of nameservers
*/
public function createCached($config, LoopInterface $loop = null, CacheInterface $cache = null)
public function createCached($config, ?LoopInterface $loop = null, ?CacheInterface $cache = null)
{
// default to keeping maximum of 256 responses in cache unless explicitly given
if (!($cache instanceof CacheInterface)) {
Expand Down

0 comments on commit c15a0d6

Please sign in to comment.