Skip to content

Commit

Permalink
[PHP 8.4] Fixes for implicit nullability deprecation
Browse files Browse the repository at this point in the history
Fixes all issues that emit deprecation notices on PHP 8.4 for implicit nullable parameter type declarations.

See:
 - [RFC](https://wiki.php.net/rfc/deprecate-implicitly-nullable-types)
 - [PHP 8.4: Implicitly nullable parameter declarations deprecated](https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated)
  • Loading branch information
Ayesh committed Mar 15, 2024
1 parent 7a10423 commit 6931c96
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion phpseclib/Crypt/Common/AsymmetricKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public static function loadParametersFormat(string $type, $key): AsymmetricKey
*
* @param string|null $method optional
*/
protected static function validatePlugin(string $format, string $type, string $method = null)
protected static function validatePlugin(string $format, string $type, ?string $method = null)
{
$type = strtolower($type);
if (!isset(self::$plugins[static::ALGORITHM][$format][$type])) {
Expand Down
4 changes: 2 additions & 2 deletions phpseclib/Crypt/Common/Formats/Keys/PKCS8.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ protected static function load($key, ?string $password = null): array
* @param string $publicKey optional
* @param array $options optional
*/
protected static function wrapPrivateKey(string $key, $attr, $params, $password, string $oid = null, string $publicKey = '', array $options = []): string
protected static function wrapPrivateKey(string $key, $attr, $params, $password, ?string $oid = null, string $publicKey = '', array $options = []): string
{
self::initialize_static_variables();

Expand Down Expand Up @@ -610,7 +610,7 @@ protected static function wrapPrivateKey(string $key, $attr, $params, $password,
/**
* Wrap a public key appropriately
*/
protected static function wrapPublicKey(string $key, $params, string $oid = null): string
protected static function wrapPublicKey(string $key, $params, ?string $oid = null): string
{
self::initialize_static_variables();

Expand Down
2 changes: 1 addition & 1 deletion phpseclib/Crypt/Common/SymmetricKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public function enablePoly1305(): void
* @throws LengthException if the key isn't long enough
* @throws BadMethodCallException if Poly1305 is enabled whilst in GCM mode
*/
public function setPoly1305Key(string $key = null): void
public function setPoly1305Key(?string $key = null): void
{
if ($this->mode == self::MODE_GCM) {
throw new BadMethodCallException('Poly1305 cannot be used in GCM mode');
Expand Down
2 changes: 1 addition & 1 deletion phpseclib/Crypt/EC.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function getSignatureFormat(): string
* @see self::verify()
* @see self::sign()
*/
public function withContext(string $context = null): EC
public function withContext(?string $context = null): EC
{
if (!$this->curve instanceof TwistedEdwardsCurve) {
throw new UnsupportedCurveException('Only Ed25519 and Ed448 support contexts');
Expand Down
2 changes: 1 addition & 1 deletion phpseclib/Crypt/EC/Formats/Keys/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static function load($key, ?string $password = null): array
* @param bool $decode optional
* @return \DOMNodeList|string
*/
private static function query(\DOMXPath $xpath, string $name, string $error = null, bool $decode = true)
private static function query(\DOMXPath $xpath, string $name, ?string $error = null, bool $decode = true)
{
$query = '/';
$names = explode('/', $name);
Expand Down
30 changes: 15 additions & 15 deletions phpseclib/File/X509.php
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ public function removeDNProp(string $propName): void
/**
* Get Distinguished Name properties
*/
public function getDNProp(string $propName, array $dn = null, bool $withType = false)
public function getDNProp(string $propName, ?array $dn = null, bool $withType = false)
{
if (!isset($dn)) {
$dn = $this->dn;
Expand Down Expand Up @@ -1744,7 +1744,7 @@ public function setDN($dn, bool $merge = false, string $type = 'utf8String'): bo
* @param array|null $dn optional
* @return array|bool|string
*/
public function getDN($format = self::DN_ARRAY, array $dn = null)
public function getDN($format = self::DN_ARRAY, ?array $dn = null)
{
if (!isset($dn)) {
$dn = isset($this->currentCert['tbsCertList']) ? $this->currentCert['tbsCertList']['issuer'] : $this->dn;
Expand Down Expand Up @@ -3074,7 +3074,7 @@ private function &subArray(?array &$root, string $path, bool $create = false)
* @param bool $create optional
* @return array|false
*/
private function &extensions(?array &$root, string $path = null, bool $create = false)
private function &extensions(?array &$root, ?string $path = null, bool $create = false)
{
if (!isset($root)) {
$root = $this->currentCert;
Expand Down Expand Up @@ -3125,7 +3125,7 @@ private function &extensions(?array &$root, string $path = null, bool $create =
*
* @param string|null $path optional
*/
private function removeExtensionHelper(string $id, string $path = null): bool
private function removeExtensionHelper(string $id, ?string $path = null): bool
{
$extensions = &$this->extensions($this->currentCert, $path);

Expand Down Expand Up @@ -3157,7 +3157,7 @@ private function removeExtensionHelper(string $id, string $path = null): bool
* @param array|null $cert optional
* @param string|null $path optional
*/
private function getExtensionHelper(string $id, array $cert = null, string $path = null)
private function getExtensionHelper(string $id, ?array $cert = null, ?string $path = null)
{
$extensions = $this->extensions($cert, $path);

Expand All @@ -3180,7 +3180,7 @@ private function getExtensionHelper(string $id, array $cert = null, string $path
* @param array|null $cert optional
* @param string|null $path optional
*/
private function getExtensionsHelper(array $cert = null, string $path = null): array
private function getExtensionsHelper(?array $cert = null, ?string $path = null): array
{
$exts = $this->extensions($cert, $path);
$extensions = [];
Expand All @@ -3201,7 +3201,7 @@ private function getExtensionsHelper(array $cert = null, string $path = null): a
* @param bool $replace optional
* @param string|null $path optional
*/
private function setExtensionHelper(string $id, $value, bool $critical = false, bool $replace = true, string $path = null): bool
private function setExtensionHelper(string $id, $value, bool $critical = false, bool $replace = true, ?string $path = null): bool
{
$extensions = &$this->extensions($this->currentCert, $path, true);

Expand Down Expand Up @@ -3241,7 +3241,7 @@ public function removeExtension(string $id): bool
*
* @param array|null $cert optional
*/
public function getExtension(string $id, array $cert = null, string $path = null)
public function getExtension(string $id, ?array $cert = null, ?string $path = null)
{
return $this->getExtensionHelper($id, $cert, $path);
}
Expand All @@ -3252,7 +3252,7 @@ public function getExtension(string $id, array $cert = null, string $path = null
* @param array|null $cert optional
* @param string|null $path optional
*/
public function getExtensions(array $cert = null, string $path = null): array
public function getExtensions(?array $cert = null, ?string $path = null): array
{
return $this->getExtensionsHelper($cert, $path);
}
Expand Down Expand Up @@ -3321,7 +3321,7 @@ public function removeAttribute(string $id, int $disposition = self::ATTR_ALL):
* @param int $disposition optional
* @param array|null $csr optional
*/
public function getAttribute(string $id, int $disposition = self::ATTR_ALL, array $csr = null)
public function getAttribute(string $id, int $disposition = self::ATTR_ALL, ?array $csr = null)
{
if (empty($csr)) {
$csr = $this->currentCert;
Expand Down Expand Up @@ -3359,7 +3359,7 @@ public function getAttribute(string $id, int $disposition = self::ATTR_ALL, arra
*
* @param array|null $csr optional
*/
public function getAttributes(array $csr = null): array
public function getAttributes(?array $csr = null): array
{
if (empty($csr)) {
$csr = $this->currentCert;
Expand Down Expand Up @@ -3627,7 +3627,7 @@ private function revokedCertificate(array &$rclist, string $serial, bool $create
*
* @param string|null $date optional
*/
public function revoke(string $serial, string $date = null): bool
public function revoke(string $serial, ?string $date = null): bool
{
if (isset($this->currentCert['tbsCertList'])) {
if (is_array($rclist = &$this->subArray($this->currentCert, 'tbsCertList/revokedCertificates', true))) {
Expand Down Expand Up @@ -3682,7 +3682,7 @@ public function getRevoked(string $serial)
* @param array|null $crl optional
* @return array|bool
*/
public function listRevoked(array $crl = null)
public function listRevoked(?array $crl = null)
{
if (!isset($crl)) {
$crl = $this->currentCert;
Expand Down Expand Up @@ -3724,7 +3724,7 @@ public function removeRevokedCertificateExtension(string $serial, string $id): b
*
* @param array|null $crl optional
*/
public function getRevokedCertificateExtension(string $serial, string $id, array $crl = null)
public function getRevokedCertificateExtension(string $serial, string $id, ?array $crl = null)
{
if (!isset($crl)) {
$crl = $this->currentCert;
Expand All @@ -3745,7 +3745,7 @@ public function getRevokedCertificateExtension(string $serial, string $id, array
* @param array|null $crl optional
* @return array|bool
*/
public function getRevokedCertificateExtensions(string $serial, array $crl = null)
public function getRevokedCertificateExtensions(string $serial, ?array $crl = null)
{
if (!isset($crl)) {
$crl = $this->currentCert;
Expand Down
2 changes: 1 addition & 1 deletion phpseclib/Math/BinaryField.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function getLength(): int
/**
* Converts a base-2 string to a base-256 string
*/
public static function base2ToBase256(string $x, int $size = null): string
public static function base2ToBase256(string $x, ?int $size = null): string
{
$str = Strings::bits2bin($x);

Expand Down
2 changes: 1 addition & 1 deletion phpseclib/Math/PrimeField/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Integer extends Base
/**
* Default constructor
*/
public function __construct(int $instanceID, BigInteger $num = null)
public function __construct(int $instanceID, ?BigInteger $num = null)
{
$this->instanceID = $instanceID;
if (!isset($num)) {
Expand Down
6 changes: 3 additions & 3 deletions phpseclib/Net/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ public function truncate(string $filename, int $new_size): bool
*
* @throws UnexpectedValueException on receipt of unexpected packets
*/
public function touch(string $filename, int $time = null, int $atime = null): bool
public function touch(string $filename, ?int $time = null, ?int $atime = null): bool
{
if (!$this->precheck()) {
return false;
Expand Down Expand Up @@ -1813,7 +1813,7 @@ public function rmdir(string $dir): bool
* @throws BadFunctionCallException if you're uploading via a callback and the callback function is invalid
* @throws FileNotFoundException if you're uploading via a file and the file doesn't exist
*/
public function put(string $remote_file, $data, int $mode = self::SOURCE_STRING, int $start = -1, int $local_start = -1, callable $progressCallback = null): bool
public function put(string $remote_file, $data, int $mode = self::SOURCE_STRING, int $start = -1, int $local_start = -1, ?callable $progressCallback = null): bool
{
if (!$this->precheck()) {
return false;
Expand Down Expand Up @@ -2060,7 +2060,7 @@ private function close_handle(string $handle): bool
* @return string|bool
* @throws UnexpectedValueException on receipt of unexpected packets
*/
public function get(string $remote_file, $local_file = false, int $offset = 0, int $length = -1, callable $progressCallback = null)
public function get(string $remote_file, $local_file = false, int $offset = 0, int $length = -1, ?callable $progressCallback = null)
{
if (!$this->precheck()) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions phpseclib/Net/SSH2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2526,7 +2526,7 @@ public function getStdError(): string
* @psalm-return ($callback is callable ? bool : string|bool)
* @throws RuntimeException on connection error
*/
public function exec(string $command, callable $callback = null)
public function exec(string $command, ?callable $callback = null)
{
$this->curTimeout = $this->timeout;
$this->is_timeout = false;
Expand Down Expand Up @@ -2833,7 +2833,7 @@ public function requestAgentForwarding(): bool
* @throws InsufficientSetupException on unexpected channel status, possibly due to closure
* @see self::write()
*/
public function read(string $expect = '', int $mode = self::READ_SIMPLE, int $channel = null)
public function read(string $expect = '', int $mode = self::READ_SIMPLE, ?int $channel = null)
{
if (!$this->isAuthenticated()) {
throw new InsufficientSetupException('Operation disallowed prior to login()');
Expand Down Expand Up @@ -2892,7 +2892,7 @@ public function read(string $expect = '', int $mode = self::READ_SIMPLE, int $ch
* @throws InsufficientSetupException on unexpected channel status, possibly due to closure
* @see SSH2::read()
*/
public function write(string $cmd, int $channel = null): void
public function write(string $cmd, ?int $channel = null): void
{
if (!$this->isAuthenticated()) {
throw new InsufficientSetupException('Operation disallowed prior to login()');
Expand Down Expand Up @@ -2977,7 +2977,7 @@ public function stopSubsystem(): bool
*
* @param int|null $channel Channel id returned by self::getInteractiveChannelId()
*/
public function reset(int $channel = null): void
public function reset(?int $channel = null): void
{
if ($channel === null) {
$channel = $this->get_interactive_channel();
Expand Down Expand Up @@ -3931,7 +3931,7 @@ protected function get_channel_packet(int $client_channel, bool $skip_extended =
*
* @see self::_get_binary_packet()
*/
protected function send_binary_packet(string $data, string $logged = null): void
protected function send_binary_packet(string $data, ?string $logged = null): void
{
if (!is_resource($this->fsock) || feof($this->fsock)) {
$this->bitmap = 0;
Expand Down
2 changes: 1 addition & 1 deletion tests/PhpseclibFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class PhpseclibFunctionalTestCase extends PhpseclibTestCase
/**
* @return null
*/
protected function requireEnv(string $variable, string $message = null)
protected function requireEnv(string $variable, ?string $message = null)
{
if ($this->_getEnv($variable) === false) {
$msg = $message ? $message : sprintf(
Expand Down

0 comments on commit 6931c96

Please sign in to comment.