From 2df5d73d846400fb332caf009288407e625b77c3 Mon Sep 17 00:00:00 2001 From: Ayesh Karunaratne Date: Sat, 16 Mar 2024 02:58:44 +0700 Subject: [PATCH] [PHP 8.4] Fixes for implicit nullability deprecation 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) --- src/AsyncAwsS3/AsyncAwsS3Adapter.php | 6 +++--- src/AsyncAwsS3/S3ClientStub.php | 2 +- src/AwsS3V3/AwsS3V3Adapter.php | 4 ++-- src/AwsS3V3/S3ClientStub.php | 2 +- src/AzureBlobStorage/AzureBlobStorageAdapter.php | 2 +- src/Filesystem.php | 2 +- src/Ftp/FtpAdapter.php | 8 ++++---- src/Ftp/UnableToResolveConnectionRoot.php | 2 +- src/GoogleCloudStorage/GoogleCloudStorageAdapter.php | 4 ++-- src/InMemory/InMemoryFilesystemAdapter.php | 2 +- src/Local/LocalFilesystemAdapter.php | 4 ++-- src/PhpseclibV2/SftpAdapter.php | 4 ++-- src/PhpseclibV2/SftpConnectionProvider.php | 10 +++++----- src/PhpseclibV2/StubSftpConnectionProvider.php | 2 +- src/PhpseclibV3/SftpAdapter.php | 4 ++-- src/PhpseclibV3/SftpConnectionProvider.php | 2 +- src/PhpseclibV3/SftpConnectionProviderTest.php | 2 +- src/PhpseclibV3/UnableToAuthenticate.php | 8 ++++---- src/PhpseclibV3/UnableToConnectToSftpHost.php | 2 +- src/UnableToCheckExistence.php | 2 +- src/UnableToCopyFile.php | 2 +- src/UnableToDeleteDirectory.php | 2 +- src/UnableToDeleteFile.php | 2 +- src/UnableToMoveFile.php | 2 +- src/UnableToReadFile.php | 2 +- src/UnableToRetrieveMetadata.php | 10 +++++----- src/UnableToSetVisibility.php | 2 +- src/UnableToWriteFile.php | 2 +- 28 files changed, 49 insertions(+), 49 deletions(-) diff --git a/src/AsyncAwsS3/AsyncAwsS3Adapter.php b/src/AsyncAwsS3/AsyncAwsS3Adapter.php index cfa11910c..87427c98a 100644 --- a/src/AsyncAwsS3/AsyncAwsS3Adapter.php +++ b/src/AsyncAwsS3/AsyncAwsS3Adapter.php @@ -106,8 +106,8 @@ public function __construct( private S3Client $client, private string $bucket, string $prefix = '', - VisibilityConverter $visibility = null, - MimeTypeDetector $mimeTypeDetector = null, + ?VisibilityConverter $visibility = null, + ?MimeTypeDetector $mimeTypeDetector = null, array $forwardedOptions = self::AVAILABLE_OPTIONS, array $metadataFields = self::EXTRA_METADATA_FIELDS, ) { @@ -411,7 +411,7 @@ private function fetchFileMetadata(string $path, string $type): FileAttributes /** * @param HeadObjectOutput|AwsObject|CommonPrefix $item */ - private function mapS3ObjectMetadata($item, string $path = null): StorageAttributes + private function mapS3ObjectMetadata($item, ?string $path = null): StorageAttributes { if (null === $path) { if ($item instanceof AwsObject) { diff --git a/src/AsyncAwsS3/S3ClientStub.php b/src/AsyncAwsS3/S3ClientStub.php index 064485728..964459483 100644 --- a/src/AsyncAwsS3/S3ClientStub.php +++ b/src/AsyncAwsS3/S3ClientStub.php @@ -57,7 +57,7 @@ public function __construct(SimpleS3Client $client, $configuration = []) parent::__construct($configuration, null, new MockHttpClient()); } - public function throwExceptionWhenExecutingCommand(string $commandName, Exception $exception = null): void + public function throwExceptionWhenExecutingCommand(string $commandName, ?Exception $exception = null): void { $this->stagedExceptions[$commandName] = $exception ?? new NetworkException(); } diff --git a/src/AwsS3V3/AwsS3V3Adapter.php b/src/AwsS3V3/AwsS3V3Adapter.php index 479332121..21936b063 100644 --- a/src/AwsS3V3/AwsS3V3Adapter.php +++ b/src/AwsS3V3/AwsS3V3Adapter.php @@ -99,8 +99,8 @@ public function __construct( private S3ClientInterface $client, private string $bucket, string $prefix = '', - VisibilityConverter $visibility = null, - MimeTypeDetector $mimeTypeDetector = null, + ?VisibilityConverter $visibility = null, + ?MimeTypeDetector $mimeTypeDetector = null, private array $options = [], private bool $streamReads = true, private array $forwardedOptions = self::AVAILABLE_OPTIONS, diff --git a/src/AwsS3V3/S3ClientStub.php b/src/AwsS3V3/S3ClientStub.php index d056fb882..b9001e69a 100644 --- a/src/AwsS3V3/S3ClientStub.php +++ b/src/AwsS3V3/S3ClientStub.php @@ -69,7 +69,7 @@ public function failOnNextCopy(): void $this->throwExceptionWhenExecutingCommand('CopyObject'); } - public function throwExceptionWhenExecutingCommand(string $commandName, S3Exception $exception = null): void + public function throwExceptionWhenExecutingCommand(string $commandName, ?S3Exception $exception = null): void { $this->stagedExceptions[$commandName] = $exception ?? new S3Exception($commandName, new Command($commandName)); } diff --git a/src/AzureBlobStorage/AzureBlobStorageAdapter.php b/src/AzureBlobStorage/AzureBlobStorageAdapter.php index 7d288ff70..c29b65c68 100644 --- a/src/AzureBlobStorage/AzureBlobStorageAdapter.php +++ b/src/AzureBlobStorage/AzureBlobStorageAdapter.php @@ -63,7 +63,7 @@ public function __construct( private BlobRestProxy $client, private string $container, string $prefix = '', - MimeTypeDetector $mimeTypeDetector = null, + ?MimeTypeDetector $mimeTypeDetector = null, private int $maxResultsForContentsListing = 5000, private string $visibilityHandling = self::ON_VISIBILITY_THROW_ERROR, private ?StorageServiceSettings $serviceSettings = null, diff --git a/src/Filesystem.php b/src/Filesystem.php index 5e42f3a89..a5ee34e26 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -25,7 +25,7 @@ class Filesystem implements FilesystemOperator public function __construct( private FilesystemAdapter $adapter, array $config = [], - PathNormalizer $pathNormalizer = null, + ?PathNormalizer $pathNormalizer = null, private ?PublicUrlGenerator $publicUrlGenerator = null, private ?TemporaryUrlGenerator $temporaryUrlGenerator = null, ) { diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index 09c14f71e..102fa0171 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -56,10 +56,10 @@ class FtpAdapter implements FilesystemAdapter public function __construct( private FtpConnectionOptions $connectionOptions, - ConnectionProvider $connectionProvider = null, - ConnectivityChecker $connectivityChecker = null, - VisibilityConverter $visibilityConverter = null, - MimeTypeDetector $mimeTypeDetector = null, + ?ConnectionProvider $connectionProvider = null, + ?ConnectivityChecker $connectivityChecker = null, + ?VisibilityConverter $visibilityConverter = null, + ?MimeTypeDetector $mimeTypeDetector = null, private bool $detectMimeTypeUsingPath = false, ) { $this->systemType = $this->connectionOptions->systemType(); diff --git a/src/Ftp/UnableToResolveConnectionRoot.php b/src/Ftp/UnableToResolveConnectionRoot.php index 7bbf2b918..d0a0735ae 100644 --- a/src/Ftp/UnableToResolveConnectionRoot.php +++ b/src/Ftp/UnableToResolveConnectionRoot.php @@ -9,7 +9,7 @@ final class UnableToResolveConnectionRoot extends RuntimeException implements FtpConnectionException { - private function __construct(string $message, Throwable $previous = null) + private function __construct(string $message, ?Throwable $previous = null) { parent::__construct($message, 0, $previous); } diff --git a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php index 95e5298f7..b180f72b5 100644 --- a/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php +++ b/src/GoogleCloudStorage/GoogleCloudStorageAdapter.php @@ -58,9 +58,9 @@ class GoogleCloudStorageAdapter implements FilesystemAdapter, PublicUrlGenerator public function __construct( private Bucket $bucket, string $prefix = '', - VisibilityHandler $visibilityHandler = null, + ?VisibilityHandler $visibilityHandler = null, private string $defaultVisibility = Visibility::PRIVATE, - MimeTypeDetector $mimeTypeDetector = null + ?MimeTypeDetector $mimeTypeDetector = null ) { $this->prefixer = new PathPrefixer($prefix); $this->visibilityHandler = $visibilityHandler ?? new PortableVisibilityHandler(); diff --git a/src/InMemory/InMemoryFilesystemAdapter.php b/src/InMemory/InMemoryFilesystemAdapter.php index 4d1182060..d77435ce6 100644 --- a/src/InMemory/InMemoryFilesystemAdapter.php +++ b/src/InMemory/InMemoryFilesystemAdapter.php @@ -32,7 +32,7 @@ class InMemoryFilesystemAdapter implements FilesystemAdapter public function __construct( private string $defaultVisibility = Visibility::PUBLIC, - MimeTypeDetector $mimeTypeDetector = null + ?MimeTypeDetector $mimeTypeDetector = null ) { $this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector(); } diff --git a/src/Local/LocalFilesystemAdapter.php b/src/Local/LocalFilesystemAdapter.php index 58694871e..2b2e095dd 100644 --- a/src/Local/LocalFilesystemAdapter.php +++ b/src/Local/LocalFilesystemAdapter.php @@ -71,10 +71,10 @@ class LocalFilesystemAdapter implements FilesystemAdapter, ChecksumProvider public function __construct( string $location, - VisibilityConverter $visibility = null, + ?VisibilityConverter $visibility = null, private int $writeFlags = LOCK_EX, private int $linkHandling = self::DISALLOW_LINKS, - MimeTypeDetector $mimeTypeDetector = null, + ?MimeTypeDetector $mimeTypeDetector = null, bool $lazyRootCreation = false, bool $useInconclusiveMimeTypeFallback = false, ) { diff --git a/src/PhpseclibV2/SftpAdapter.php b/src/PhpseclibV2/SftpAdapter.php index e41f29c73..f2e5d6b1f 100644 --- a/src/PhpseclibV2/SftpAdapter.php +++ b/src/PhpseclibV2/SftpAdapter.php @@ -57,8 +57,8 @@ class SftpAdapter implements FilesystemAdapter public function __construct( ConnectionProvider $connectionProvider, string $root, - VisibilityConverter $visibilityConverter = null, - MimeTypeDetector $mimeTypeDetector = null, + ?VisibilityConverter $visibilityConverter = null, + ?MimeTypeDetector $mimeTypeDetector = null, private bool $detectMimeTypeUsingPath = false, ) { $this->connectionProvider = $connectionProvider; diff --git a/src/PhpseclibV2/SftpConnectionProvider.php b/src/PhpseclibV2/SftpConnectionProvider.php index b1b793d79..3d7df000d 100644 --- a/src/PhpseclibV2/SftpConnectionProvider.php +++ b/src/PhpseclibV2/SftpConnectionProvider.php @@ -77,15 +77,15 @@ class SftpConnectionProvider implements ConnectionProvider public function __construct( string $host, string $username, - string $password = null, - string $privateKey = null, - string $passphrase = null, + ?string $password = null, + ?string $privateKey = null, + ?string $passphrase = null, int $port = 22, bool $useAgent = false, int $timeout = 10, int $maxTries = 4, - string $hostFingerprint = null, - ConnectivityChecker $connectivityChecker = null, + ?string $hostFingerprint = null, + ?ConnectivityChecker $connectivityChecker = null, private bool $disableStatCache = true, ) { $this->host = $host; diff --git a/src/PhpseclibV2/StubSftpConnectionProvider.php b/src/PhpseclibV2/StubSftpConnectionProvider.php index bb979de07..8ee41e732 100644 --- a/src/PhpseclibV2/StubSftpConnectionProvider.php +++ b/src/PhpseclibV2/StubSftpConnectionProvider.php @@ -39,7 +39,7 @@ class StubSftpConnectionProvider implements ConnectionProvider public function __construct( string $host, string $username, - string $password = null, + ?string $password = null, int $port = 22 ) { $this->host = $host; diff --git a/src/PhpseclibV3/SftpAdapter.php b/src/PhpseclibV3/SftpAdapter.php index 5fa5f9dee..2f6012751 100644 --- a/src/PhpseclibV3/SftpAdapter.php +++ b/src/PhpseclibV3/SftpAdapter.php @@ -38,8 +38,8 @@ class SftpAdapter implements FilesystemAdapter public function __construct( private ConnectionProvider $connectionProvider, string $root, - VisibilityConverter $visibilityConverter = null, - MimeTypeDetector $mimeTypeDetector = null, + ?VisibilityConverter $visibilityConverter = null, + ?MimeTypeDetector $mimeTypeDetector = null, private bool $detectMimeTypeUsingPath = false, ) { $this->prefixer = new PathPrefixer($root); diff --git a/src/PhpseclibV3/SftpConnectionProvider.php b/src/PhpseclibV3/SftpConnectionProvider.php index 5869f3226..fd340aed2 100644 --- a/src/PhpseclibV3/SftpConnectionProvider.php +++ b/src/PhpseclibV3/SftpConnectionProvider.php @@ -40,7 +40,7 @@ public function __construct( private int $timeout = 10, private int $maxTries = 4, private ?string $hostFingerprint = null, - ConnectivityChecker $connectivityChecker = null, + ?ConnectivityChecker $connectivityChecker = null, private array $preferredAlgorithms = [], private bool $disableStatCache = true, ) { diff --git a/src/PhpseclibV3/SftpConnectionProviderTest.php b/src/PhpseclibV3/SftpConnectionProviderTest.php index 6ba3bb680..6bcb82391 100644 --- a/src/PhpseclibV3/SftpConnectionProviderTest.php +++ b/src/PhpseclibV3/SftpConnectionProviderTest.php @@ -373,7 +373,7 @@ private function computeFingerPrint(string $publicKey): string * * @throws Throwable */ - public function runWithRetries(callable $scenario, string $expected = null): void + public function runWithRetries(callable $scenario, ?string $expected = null): void { $tries = 0; start: diff --git a/src/PhpseclibV3/UnableToAuthenticate.php b/src/PhpseclibV3/UnableToAuthenticate.php index b4906fe2d..c02ace44d 100644 --- a/src/PhpseclibV3/UnableToAuthenticate.php +++ b/src/PhpseclibV3/UnableToAuthenticate.php @@ -11,23 +11,23 @@ class UnableToAuthenticate extends RuntimeException implements FilesystemExcepti { private ?string $connectionError; - public function __construct(string $message, string $lastError = null) + public function __construct(string $message, ?string $lastError = null) { parent::__construct($message); $this->connectionError = $lastError; } - public static function withPassword(string $lastError = null): UnableToAuthenticate + public static function withPassword(?string $lastError = null): UnableToAuthenticate { return new UnableToAuthenticate('Unable to authenticate using a password.', $lastError); } - public static function withPrivateKey(string $lastError = null): UnableToAuthenticate + public static function withPrivateKey(?string $lastError = null): UnableToAuthenticate { return new UnableToAuthenticate('Unable to authenticate using a private key.', $lastError); } - public static function withSshAgent(string $lastError = null): UnableToAuthenticate + public static function withSshAgent(?string $lastError = null): UnableToAuthenticate { return new UnableToAuthenticate('Unable to authenticate using an SSH agent.', $lastError); } diff --git a/src/PhpseclibV3/UnableToConnectToSftpHost.php b/src/PhpseclibV3/UnableToConnectToSftpHost.php index 052903fbd..6fcaa4930 100644 --- a/src/PhpseclibV3/UnableToConnectToSftpHost.php +++ b/src/PhpseclibV3/UnableToConnectToSftpHost.php @@ -10,7 +10,7 @@ class UnableToConnectToSftpHost extends RuntimeException implements FilesystemException { - public static function atHostname(string $host, Throwable $previous = null): UnableToConnectToSftpHost + public static function atHostname(string $host, ?Throwable $previous = null): UnableToConnectToSftpHost { return new UnableToConnectToSftpHost("Unable to connect to host: $host", 0, $previous); } diff --git a/src/UnableToCheckExistence.php b/src/UnableToCheckExistence.php index 52c2bd697..5f204d35e 100644 --- a/src/UnableToCheckExistence.php +++ b/src/UnableToCheckExistence.php @@ -14,7 +14,7 @@ final public function __construct(string $message = "", int $code = 0, ?Throwabl parent::__construct($message, $code, $previous); } - public static function forLocation(string $path, Throwable $exception = null): static + public static function forLocation(string $path, ?Throwable $exception = null): static { return new static("Unable to check existence for: {$path}", 0, $exception); } diff --git a/src/UnableToCopyFile.php b/src/UnableToCopyFile.php index a27d66e48..543124c1c 100644 --- a/src/UnableToCopyFile.php +++ b/src/UnableToCopyFile.php @@ -32,7 +32,7 @@ public function destination(): string public static function fromLocationTo( string $sourcePath, string $destinationPath, - Throwable $previous = null + ?Throwable $previous = null ): UnableToCopyFile { $e = new static("Unable to copy file from $sourcePath to $destinationPath", 0 , $previous); $e->source = $sourcePath; diff --git a/src/UnableToDeleteDirectory.php b/src/UnableToDeleteDirectory.php index eeeab24b2..bf6cf3b98 100644 --- a/src/UnableToDeleteDirectory.php +++ b/src/UnableToDeleteDirectory.php @@ -22,7 +22,7 @@ final class UnableToDeleteDirectory extends RuntimeException implements Filesyst public static function atLocation( string $location, string $reason = '', - Throwable $previous = null + ?Throwable $previous = null ): UnableToDeleteDirectory { $e = new static(rtrim("Unable to delete directory located at: {$location}. {$reason}"), 0, $previous); $e->location = $location; diff --git a/src/UnableToDeleteFile.php b/src/UnableToDeleteFile.php index 18f7215cc..e388f3320 100644 --- a/src/UnableToDeleteFile.php +++ b/src/UnableToDeleteFile.php @@ -19,7 +19,7 @@ final class UnableToDeleteFile extends RuntimeException implements FilesystemOpe */ private $reason; - public static function atLocation(string $location, string $reason = '', Throwable $previous = null): UnableToDeleteFile + public static function atLocation(string $location, string $reason = '', ?Throwable $previous = null): UnableToDeleteFile { $e = new static(rtrim("Unable to delete file located at: {$location}. {$reason}"), 0, $previous); $e->location = $location; diff --git a/src/UnableToMoveFile.php b/src/UnableToMoveFile.php index f5c68097c..e14254058 100644 --- a/src/UnableToMoveFile.php +++ b/src/UnableToMoveFile.php @@ -37,7 +37,7 @@ public function destination(): string public static function fromLocationTo( string $sourcePath, string $destinationPath, - Throwable $previous = null + ?Throwable $previous = null ): UnableToMoveFile { $message = $previous?->getMessage() ?? "Unable to move file from $sourcePath to $destinationPath"; $e = new static($message, 0, $previous); diff --git a/src/UnableToReadFile.php b/src/UnableToReadFile.php index 766b56309..b895b86fd 100644 --- a/src/UnableToReadFile.php +++ b/src/UnableToReadFile.php @@ -19,7 +19,7 @@ final class UnableToReadFile extends RuntimeException implements FilesystemOpera */ private $reason = ''; - public static function fromLocation(string $location, string $reason = '', Throwable $previous = null): UnableToReadFile + public static function fromLocation(string $location, string $reason = '', ?Throwable $previous = null): UnableToReadFile { $e = new static(rtrim("Unable to read file from location: {$location}. {$reason}"), 0, $previous); $e->location = $location; diff --git a/src/UnableToRetrieveMetadata.php b/src/UnableToRetrieveMetadata.php index 11cec7f99..f7e3fde4c 100644 --- a/src/UnableToRetrieveMetadata.php +++ b/src/UnableToRetrieveMetadata.php @@ -24,27 +24,27 @@ final class UnableToRetrieveMetadata extends RuntimeException implements Filesys */ private $reason; - public static function lastModified(string $location, string $reason = '', Throwable $previous = null): self + public static function lastModified(string $location, string $reason = '', ?Throwable $previous = null): self { return static::create($location, FileAttributes::ATTRIBUTE_LAST_MODIFIED, $reason, $previous); } - public static function visibility(string $location, string $reason = '', Throwable $previous = null): self + public static function visibility(string $location, string $reason = '', ?Throwable $previous = null): self { return static::create($location, FileAttributes::ATTRIBUTE_VISIBILITY, $reason, $previous); } - public static function fileSize(string $location, string $reason = '', Throwable $previous = null): self + public static function fileSize(string $location, string $reason = '', ?Throwable $previous = null): self { return static::create($location, FileAttributes::ATTRIBUTE_FILE_SIZE, $reason, $previous); } - public static function mimeType(string $location, string $reason = '', Throwable $previous = null): self + public static function mimeType(string $location, string $reason = '', ?Throwable $previous = null): self { return static::create($location, FileAttributes::ATTRIBUTE_MIME_TYPE, $reason, $previous); } - public static function create(string $location, string $type, string $reason = '', Throwable $previous = null): self + public static function create(string $location, string $type, string $reason = '', ?Throwable $previous = null): self { $e = new static("Unable to retrieve the $type for file at location: $location. {$reason}", 0, $previous); $e->reason = $reason; diff --git a/src/UnableToSetVisibility.php b/src/UnableToSetVisibility.php index 5862d0e0c..d0126098d 100644 --- a/src/UnableToSetVisibility.php +++ b/src/UnableToSetVisibility.php @@ -27,7 +27,7 @@ public function reason(): string return $this->reason; } - public static function atLocation(string $filename, string $extraMessage = '', Throwable $previous = null): self + public static function atLocation(string $filename, string $extraMessage = '', ?Throwable $previous = null): self { $message = "Unable to set visibility for file {$filename}. $extraMessage"; $e = new static(rtrim($message), 0, $previous); diff --git a/src/UnableToWriteFile.php b/src/UnableToWriteFile.php index 5de786658..fb9a1006f 100644 --- a/src/UnableToWriteFile.php +++ b/src/UnableToWriteFile.php @@ -19,7 +19,7 @@ final class UnableToWriteFile extends RuntimeException implements FilesystemOper */ private $reason; - public static function atLocation(string $location, string $reason = '', Throwable $previous = null): UnableToWriteFile + public static function atLocation(string $location, string $reason = '', ?Throwable $previous = null): UnableToWriteFile { $e = new static(rtrim("Unable to write file at location: {$location}. {$reason}"), 0, $previous); $e->location = $location;