Skip to content

Commit

Permalink
Merge pull request #1722 from jnoordsij/replace-ternary-with-null-coa…
Browse files Browse the repository at this point in the history
…lescing

Replace various short-ternary operators with null coalescing ones
  • Loading branch information
frankdejonge authored Nov 6, 2023
2 parents 593da2e + 8168c28 commit 45c1e8e
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 27 deletions.
5 changes: 3 additions & 2 deletions src/AsyncAwsS3/AsyncAwsS3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public function __construct(
array $metadataFields = self::EXTRA_METADATA_FIELDS,
) {
$this->prefixer = new PathPrefixer($prefix);
$this->visibility = $visibility ?: new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
$this->visibility = $visibility ?? new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
$this->forwardedOptions = $forwardedOptions;
$this->metadataFields = $metadataFields;
}
Expand Down Expand Up @@ -315,6 +315,7 @@ public function move(string $source, string $destination, Config $config): void
public function copy(string $source, string $destination, Config $config): void
{
try {

$visibility = $config->get(Config::OPTION_VISIBILITY);

if ($visibility === null && $config->get('retain_visibility', true)) {
Expand Down
2 changes: 1 addition & 1 deletion src/AsyncAwsS3/S3ClientStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct(SimpleS3Client $client, $configuration = [])

public function throwExceptionWhenExecutingCommand(string $commandName, Exception $exception = null): void
{
$this->stagedExceptions[$commandName] = $exception ?: new NetworkException();
$this->stagedExceptions[$commandName] = $exception ?? new NetworkException();
}

public function stageResultForCommand(string $commandName, Result $result): void
Expand Down
8 changes: 4 additions & 4 deletions src/AwsS3V3/AwsS3V3Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function __construct(
private array $multipartUploadOptions = self::MUP_AVAILABLE_OPTIONS,
) {
$this->prefixer = new PathPrefixer($prefix);
$this->visibility = $visibility ?: new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
$this->visibility = $visibility ?? new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
}

public function fileExists(string $path): bool
Expand Down Expand Up @@ -397,8 +397,8 @@ private function retrievePaginatedListing(array $options): Generator
$resultPaginator = $this->client->getPaginator('ListObjectsV2', $options + $this->options);

foreach ($resultPaginator as $result) {
yield from ($result->get('CommonPrefixes') ?: []);
yield from ($result->get('Contents') ?: []);
yield from ($result->get('CommonPrefixes') ?? []);
yield from ($result->get('Contents') ?? []);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/AwsS3V3/S3ClientStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function failOnNextCopy(): void

public function throwExceptionWhenExecutingCommand(string $commandName, S3Exception $exception = null): void
{
$this->stagedExceptions[$commandName] = $exception ?: new S3Exception($commandName, new Command($commandName));
$this->stagedExceptions[$commandName] = $exception ?? new S3Exception($commandName, new Command($commandName));
}

public function throw500ExceptionWhenExecutingCommand(string $commandName): void
Expand Down
6 changes: 3 additions & 3 deletions src/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(
private ?TemporaryUrlGenerator $temporaryUrlGenerator = null,
) {
$this->config = new Config($config);
$this->pathNormalizer = $pathNormalizer ?: new WhitespacePathNormalizer();
$this->pathNormalizer = $pathNormalizer ?? new WhitespacePathNormalizer();
}

public function fileExists(string $location): bool
Expand Down Expand Up @@ -183,15 +183,15 @@ public function visibility(string $path): string
public function publicUrl(string $path, array $config = []): string
{
$this->publicUrlGenerator ??= $this->resolvePublicUrlGenerator()
?: throw UnableToGeneratePublicUrl::noGeneratorConfigured($path);
?? throw UnableToGeneratePublicUrl::noGeneratorConfigured($path);
$config = $this->config->extend($config);

return $this->publicUrlGenerator->publicUrl($path, $config);
}

public function temporaryUrl(string $path, DateTimeInterface $expiresAt, array $config = []): string
{
$generator = $this->temporaryUrlGenerator ?: $this->adapter;
$generator = $this->temporaryUrlGenerator ?? $this->adapter;

if ($generator instanceof TemporaryUrlGenerator) {
return $generator->temporaryUrl($path, $expiresAt, $this->config->extend($config));
Expand Down
8 changes: 4 additions & 4 deletions src/Ftp/FtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public function __construct(
private bool $detectMimeTypeUsingPath = false,
) {
$this->systemType = $this->connectionOptions->systemType();
$this->connectionProvider = $connectionProvider ?: new FtpConnectionProvider();
$this->connectivityChecker = $connectivityChecker ?: new NoopCommandConnectivityChecker();
$this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
$this->connectionProvider = $connectionProvider ?? new FtpConnectionProvider();
$this->connectivityChecker = $connectivityChecker ?? new NoopCommandConnectivityChecker();
$this->visibilityConverter = $visibilityConverter ?? new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
$this->useRawListOptions = $connectionOptions->useRawListOptions();
}

Expand Down
4 changes: 2 additions & 2 deletions src/GoogleCloudStorage/GoogleCloudStorageAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public function __construct(
MimeTypeDetector $mimeTypeDetector = null
) {
$this->prefixer = new PathPrefixer($prefix);
$this->visibilityHandler = $visibilityHandler ?: new PortableVisibilityHandler();
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
$this->visibilityHandler = $visibilityHandler ?? new PortableVisibilityHandler();
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
}

public function publicUrl(string $path, Config $config): string
Expand Down
2 changes: 1 addition & 1 deletion src/GoogleCloudStorage/StubRiggedBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function upload($data, array $options = [])

private function setupTrigger(string $method, string $name, ?Throwable $throwable): void
{
$this->triggers[$method][$name] = $throwable ?: new LogicException('unknown error');
$this->triggers[$method][$name] = $throwable ?? new LogicException('unknown error');
}

private function pushTrigger(string $method, string $name): void
Expand Down
2 changes: 1 addition & 1 deletion src/InMemory/InMemoryFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InMemoryFile
public function updateContents(string $contents, ?int $timestamp): void
{
$this->contents = $contents;
$this->lastModified = $timestamp ?: time();
$this->lastModified = $timestamp ?? time();
}

public function lastModified(): int
Expand Down
2 changes: 1 addition & 1 deletion src/InMemory/InMemoryFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
private string $defaultVisibility = Visibility::PUBLIC,
MimeTypeDetector $mimeTypeDetector = null
) {
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
}

public function fileExists(string $path): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Local/LocalFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct(
$visibility ??= new PortableVisibilityConverter();
$this->visibility = $visibility;
$this->rootLocation = $location;
$this->mimeTypeDetector = $mimeTypeDetector ?: new FallbackMimeTypeDetector(new FinfoMimeTypeDetector());
$this->mimeTypeDetector = $mimeTypeDetector ?? new FallbackMimeTypeDetector(new FinfoMimeTypeDetector());

if ( ! $lazyRootCreation) {
$this->ensureRootDirectoryExists();
Expand Down
4 changes: 2 additions & 2 deletions src/PhpseclibV2/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function __construct(
) {
$this->connectionProvider = $connectionProvider;
$this->prefixer = new PathPrefixer($root);
$this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
$this->visibilityConverter = $visibilityConverter ?? new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
}

public function fileExists(string $path): bool
Expand Down
2 changes: 1 addition & 1 deletion src/PhpseclibV2/SftpConnectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function __construct(
$this->port = $port;
$this->timeout = $timeout;
$this->hostFingerprint = $hostFingerprint;
$this->connectivityChecker = $connectivityChecker ?: new SimpleConnectivityChecker();
$this->connectivityChecker = $connectivityChecker ?? new SimpleConnectivityChecker();
$this->maxTries = $maxTries;
}

Expand Down
4 changes: 2 additions & 2 deletions src/PhpseclibV3/SftpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function __construct(
private bool $detectMimeTypeUsingPath = false,
) {
$this->prefixer = new PathPrefixer($root);
$this->visibilityConverter = $visibilityConverter ?: new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?: new FinfoMimeTypeDetector();
$this->visibilityConverter = $visibilityConverter ?? new PortableVisibilityConverter();
$this->mimeTypeDetector = $mimeTypeDetector ?? new FinfoMimeTypeDetector();
}

public function fileExists(string $path): bool
Expand Down
2 changes: 1 addition & 1 deletion src/PhpseclibV3/SftpConnectionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
private array $preferredAlgorithms = [],
private bool $disableStatCache = true,
) {
$this->connectivityChecker = $connectivityChecker ?: new SimpleConnectivityChecker();
$this->connectivityChecker = $connectivityChecker ?? new SimpleConnectivityChecker();
}

public function provideConnection(): SFTP
Expand Down

0 comments on commit 45c1e8e

Please sign in to comment.