Skip to content

Commit

Permalink
Make implicit nullable types explicit (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Mar 21, 2024
1 parent a8af9f5 commit b00528b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class Certificate
* @param string $certFile Certificate file with the certificate + intermediaries.
* @param string|null $keyFile Key file with the corresponding private key or `null` if the key is in $certFile.
*/
public function __construct(string $certFile, string $keyFile = null)
public function __construct(string $certFile, ?string $keyFile = null)
{
$this->certFile = $certFile;
$this->keyFile = $keyFile ?? $certFile;
Expand Down
8 changes: 4 additions & 4 deletions src/ClientTlsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function getVerificationDepth(): int
*
* @return self Cloned, modified instance.
*/
public function withCiphers(string $ciphers = null): self
public function withCiphers(?string $ciphers = null): self
{
$clone = clone $this;
$clone->ciphers = $ciphers;
Expand All @@ -202,7 +202,7 @@ public function getCiphers(): string
*
* @return self Cloned, modified instance.
*/
public function withCaFile(string $cafile = null): self
public function withCaFile(?string $cafile = null): self
{
$clone = clone $this;
$clone->caFile = $cafile;
Expand All @@ -225,7 +225,7 @@ public function getCaFile(): ?string
*
* @return self Cloned, modified instance.
*/
public function withCaPath(string $capath = null): self
public function withCaPath(?string $capath = null): self
{
$clone = clone $this;
$clone->caPath = $capath;
Expand Down Expand Up @@ -361,7 +361,7 @@ public function getSecurityLevel(): int
*
* @return self Cloned, modified instance.
*/
public function withCertificate(Certificate $certificate = null): self
public function withCertificate(?Certificate $certificate = null): self
{
$clone = clone $this;
$clone->certificate = $certificate;
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function shutdownTls($socket): Promise
*
* @throws \Error If an invalid option has been passed.
*/
function normalizeBindToOption(string $bindTo = null)
function normalizeBindToOption(?string $bindTo = null)
{
if ($bindTo === null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/PendingAcceptError.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class PendingAcceptError extends \Error
public function __construct(
string $message = 'The previous accept operation must complete before accept can be called again',
int $code = 0,
\Throwable $previous = null
?\Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PendingReceiveError.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class PendingReceiveError extends \Error
public function __construct(
string $message = 'The previous receive operation must complete before receive can be called again',
int $code = 0,
\Throwable $previous = null
?\Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand Down
10 changes: 5 additions & 5 deletions src/ServerTlsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function getMinimumVersion(): int
*
* @return self Cloned, modified instance.
*/
public function withPeerName(string $peerName = null): self
public function withPeerName(?string $peerName = null): self
{
$clone = clone $this;
$clone->peerName = $peerName;
Expand Down Expand Up @@ -171,7 +171,7 @@ public function getVerificationDepth(): int
*
* @return self Cloned, modified instance.
*/
public function withCiphers(string $ciphers = null): self
public function withCiphers(?string $ciphers = null): self
{
$clone = clone $this;
$clone->ciphers = $ciphers;
Expand All @@ -194,7 +194,7 @@ public function getCiphers(): string
*
* @return self Cloned, modified instance.
*/
public function withCaFile(string $cafile = null): self
public function withCaFile(?string $cafile = null): self
{
$clone = clone $this;
$clone->caFile = $cafile;
Expand All @@ -217,7 +217,7 @@ public function getCaFile(): ?string
*
* @return self Cloned, modified instance.
*/
public function withCaPath(string $capath = null): self
public function withCaPath(?string $capath = null): self
{
$clone = clone $this;
$clone->caPath = $capath;
Expand Down Expand Up @@ -276,7 +276,7 @@ public function hasPeerCapturing(): bool
*
* @return self Cloned, modified instance.
*/
public function withDefaultCertificate(Certificate $defaultCertificate = null): self
public function withDefaultCertificate(?Certificate $defaultCertificate = null): self
{
$clone = clone $this;
$clone->defaultCertificate = $defaultCertificate;
Expand Down
4 changes: 2 additions & 2 deletions src/SocketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ interface SocketPool
*/
public function checkout(
string $uri,
ConnectContext $context = null,
CancellationToken $token = null
?ConnectContext $context = null,
?CancellationToken $token = null
): Promise;

/**
Expand Down
8 changes: 4 additions & 4 deletions src/UnlimitedSocketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function __construct(int $idleTimeout = 10000, ?Connector $connector = nu
/** @inheritdoc */
public function checkout(
string $uri,
ConnectContext $context = null,
CancellationToken $token = null
?ConnectContext $context = null,
?CancellationToken $token = null
): Promise {
// A request might already be cancelled before we reach the checkout, so do not even attempt to checkout in that
// case. The weird logic is required to throw the token's exception instead of creating a new one.
Expand Down Expand Up @@ -203,8 +203,8 @@ private function normalizeUri(string $uri): array
private function checkoutNewSocket(
string $uri,
string $cacheKey,
ConnectContext $connectContext = null,
CancellationToken $token = null
?ConnectContext $connectContext = null,
?CancellationToken $token = null
): Promise {
return call(function () use ($uri, $cacheKey, $connectContext, $token) {
$this->pendingCount[$uri] = ($this->pendingCount[$uri] ?? 0) + 1;
Expand Down
4 changes: 2 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function listen(string $uri, ?BindContext $context = null): Server
*
* @return Connector
*/
function connector(Connector $connector = null): Connector
function connector(?Connector $connector = null): Connector
{
if ($connector === null) {
if ($connector = Loop::getState(LOOP_CONNECTOR_IDENTIFIER)) {
Expand All @@ -64,7 +64,7 @@ function connector(Connector $connector = null): Connector
* @throws ConnectException
* @throws CancelledException
*/
function connect(string $uri, ConnectContext $context = null, CancellationToken $token = null): Promise
function connect(string $uri, ?ConnectContext $context = null, ?CancellationToken $token = null): Promise
{
return connector()->connect($uri, $context, $token);
}
Expand Down

0 comments on commit b00528b

Please sign in to comment.