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 4c44347 commit 2df5d73
Show file tree
Hide file tree
Showing 28 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/AsyncAwsS3/AsyncAwsS3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/AsyncAwsS3/S3ClientStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/AwsS3V3/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/AwsS3V3/S3ClientStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
2 changes: 1 addition & 1 deletion src/AzureBlobStorage/AzureBlobStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
8 changes: 4 additions & 4 deletions src/Ftp/FtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Ftp/UnableToResolveConnectionRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/GoogleCloudStorage/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/InMemory/InMemoryFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
4 changes: 2 additions & 2 deletions src/PhpseclibV2/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/PhpseclibV2/SftpConnectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/PhpseclibV2/StubSftpConnectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpseclibV3/SftpConnectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
2 changes: 1 addition & 1 deletion src/PhpseclibV3/SftpConnectionProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/PhpseclibV3/UnableToAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/PhpseclibV3/UnableToConnectToSftpHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/UnableToCheckExistence.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/UnableToCopyFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/UnableToDeleteDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/UnableToDeleteFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/UnableToMoveFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/UnableToReadFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/UnableToRetrieveMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/UnableToSetVisibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/UnableToWriteFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2df5d73

Please sign in to comment.