8000 Add a few more ??= by tigitz · Pull Request #47649 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Add a few more ??= #47649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/Twig/Extension/DumpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function dump(Environment $env, array $context): ?string
}

$dump = fopen('php://memory', 'r+');
$this->dumper = $this->dumper ?? new HtmlDumper();
$this->dumper ??= new HtmlDumper();
$this->dumper->setCharset($env->getCharset());

foreach ($vars as $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static function createSystemCache(string $namespace, int $defaultLifetime
$opcache->setLogger($logger);
}

if (!self::$apcuSupported = self::$apcuSupported ?? ApcuAdapter::isSupported()) {
if (!self::$apcuSupported ??= ApcuAdapter::isSupported()) {
return $opcache;
}

Expand Down
22 changes: 11 additions & 11 deletions src/Symfony/Component/Cache/Adapter/CouchbaseBucketAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ private static function getOptions(string $options): array

private static function initOptions(array $options): array
{
$options['username'] = $options['username'] ?? '';
$options['password'] = $options['password'] ?? '';
$options['operationTimeout'] = $options['operationTimeout'] ?? 0;
$options['configTimeout'] = $options['configTimeout'] ?? 0;
$options['configNodeTimeout'] = $options['configNodeTimeout'] ?? 0;
$options['n1qlTimeout'] = $options['n1qlTimeout'] ?? 0;
$options['httpTimeout'] = $options['httpTimeout'] ?? 0;
$options['configDelay'] = $options['configDelay'] ?? 0;
$options['htconfigIdleTimeout'] = $options['htconfigIdleTimeout'] ?? 0;
$options['durabilityInterval'] = $options['durabilityInterval'] ?? 0;
$options['durabilityTimeout'] = $options['durabilityTimeout'] ?? 0;
$options['username'] ??= '';
$options['password'] ??= '';
$options['operationTimeout'] ??= 0;
$options['configTimeout'] ??= 0;
$options['configNodeTimeout'] ??= 0;
$options['n1qlTimeout'] ??= 0;
$options['httpTimeout'] ??= 0;
$options['configDelay'] ??= 0;
$options['htconfigIdleTimeout'] ??= 0;
$options['durabilityInterval'] ??= 0;
$options['durabilityTimeout'] ??= 0;

return $options;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class PhpFilesAdapter extends AbstractAdapter implements PruneableInterface
public function __construct(string $namespace = '', int $defaultLifetime = 0, string $directory = null, bool $appendOnly = false)
{
$this->appendOnly = $appendOnly;
self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time();
self::$startTime ??= $_SERVER['REQUEST_TIME'] ?? time();
parent::__construct('', $defaultLifetime);
$this->init($namespace, $directory);
$this->includeHandler = static function ($type, $msg, $file, $line) {
Expand All @@ -56,7 +56,7 @@ public function __construct(string $namespace = '', int $defaultLifetime = 0, st

public static function isSupported()
{
self::$startTime = self::$startTime ?? $_SERVER['REQUEST_TIME'] ?? time();
self::$startTime ??= $_SERVER['REQUEST_TIME'] ?? time();

return \function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOL) && (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) || filter_var(\ini_get('opcache.enable_cli'), \FILTER_VALIDATE_BOOL));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function canBeEnabled(): static
->beforeNormalization()
->ifArray()
->then(function (array $v) {
$v['enabled'] = $v['enabled'] ?? true;
$v['enabled'] ??= true;

return $v;
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function process(ContainerBuilder $container)
continue;
}

$event['method'] = $event['method'] ?? '__invoke';
$event['method'] ??= '__invoke';
$event['event'] = $this->getEventFromTypeDeclaration($container, $id, $event['method']);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/Internal/AmpListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(array &$info, array $pinSha256, \Closure $onProgress

public function startRequest(Request $request): Promise
{
$this->info['start_time'] = $this->info['start_time'] ?? microtime(true);
$this->info['start_time'] ??= microtime(true);
($this->onProgress)();

return new Success();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class CurlClientState extends ClientState

public function __construct(int $maxHostConnections, int $maxPendingPushes)
{
self::$curlVersion = self::$curlVersion ?? curl_version();
self::$curlVersion ??= curl_version();

$this->handle = curl_multi_init();
$this->dnsCache = new DnsCache();
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpClient/Response/CurlResponse.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct(CurlClientState $multi, \CurlHandle|string $ch, arra
$this->info['http_method'] = $method;
$this->info['user_data'] = $options['user_data'] ?? null;
$this->info['max_duration'] = $options['max_duration'] ?? null;
$this->info['start_time'] = $this->info['start_time'] ?? microtime(true);
$this->info['start_time'] ??= microtime(true);
$this->info['original_url'] = $originalUrl ?? $this->info['url'] ?? curl_getinfo($ch, \CURLINFO_EFFECTIVE_URL);
$info = &$this->info;
$headers = &$this->headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected function loadSession()

foreach ($bags as $bag) {
$key = $bag->getStorageKey();
$this->data[$key] = $this->data[$key] ?? [];
$this->data[$key] ??= [];
$bag->initialize($this->data[$key]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function initialize(): void
$options = array_merge($options, $this->streamContextOptions);
}
// do it unconditionnally as it will be used by STARTTLS as well if supported
$options['ssl']['crypto_method'] = $options['ssl']['crypto_method'] ?? \STREAM_CRYPTO_METHOD_TLS_CLIENT | \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT | \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
$options['ssl']['crypto_method'] ??= \STREAM_CRYPTO_METHOD_TLS_CLIENT | \STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT | \STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
$streamContext = stream_context_create($options);

$timeout = $this->getTimeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ private function publishOnExchange(\AMQPExchange $exchange, string $body, string
{
$attributes = $amqpStamp ? $amqpStamp->getAttributes() : [];
$attributes['headers'] = array_merge($attributes['headers'] ?? [], $headers);
$attributes['delivery_mode'] = $attributes['delivery_mode'] ?? 2;
$attributes['timestamp'] = $attributes['timestamp'] ?? time();
$attributes['delivery_mode'] ??= 2;
$attributes['timestamp'] ??= time();

$exchange->publish(
$body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static function fromDsn(string $dsn, array $options = [], \Redis|\RedisCl
$options['host'] = $parsedUrl['host'] ?? $options['host'];
$options['port'] = $parsedUrl['port'] ?? $options['port'];
// See: https://github.com/phpredis/phpredis/#auth
$options['auth'] = $options['auth'] ?? (null !== $pass && null !== $user ? [$user, $pass] : ($pass ?? $user));
$options['auth'] ??= null !== $pass && null !== $user ? [$user, $pass] : ($pass ?? $user);

$pathParts = explode('/', rtrim($parsedUrl['path'] ?? '', '/'));
$options['stream'] = $pathParts[1] ?? $options['stream'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function doSend(MessageInterface $message): SentMessage

$options['title'] = $message->getSubject();
$options['body'] = $message->getContent();
$options['data'] = $options['data'] ?? [];
$options['data'] ??= [];

$response = $this->client->request('POST', $endpoint, [
'headers' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ protected function doSend(MessageInterface $message): SentMessage
if (null === $options['to']) {
throw new InvalidArgumentException(sprintf('The "%s" transport required the "to" option to be set.', __CLASS__));
}
$options['notification'] = $options['notification'] ?? [];
$options['notification'] ??= [];
$options['notification']['body'] = $message->getSubject();
$options['data'] = $options['data'] ?? [];
$options['data'] ??= [];

$response = $this->client->request('POST', $endpoint, [
'headers' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function doSend(MessageInterface $message): SentMessage

$options = ($opts = $message->getOptions()) ? $opts->toArray() : [];

$options['text'] = $options['text'] ?? $message->getSubject();
$options['text'] ??= $message->getSubject();

$path = $message->getRecipientId() ?? $this->path;
$endpoint = sprintf('https://%s%s', $this->getEndpoint(), $path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ public function addNormalizer(string $option, \Closure $normalizer, bool $forceP
}

if ($forcePrepend) {
$this->normalizers[$option] = $this->normalizers[$option] ?? [];
$this->normalizers[$option] ??= [];
array_unshift($this->normalizers[$option], $normalizer);
} else {
$this->normalizers[$option][] = $normalizer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class NameScopeFactory
{
public function create(string $calledClassName, string $declaringClassName = null): NameScope
{
$declaringClassName = $declaringClassName ?? $calledClassName;
$declaringClassName ??= $calledClassName;

$path = explode('\\', $calledClassName);
$calledClassName = array_pop($path);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Runtime/Tests/phpt/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use Symfony\Component\Runtime\SymfonyRuntime;

$_SERVER['APP_RUNTIME_OPTIONS'] = $_SERVER['APP_RUNTIME_OPTIONS'] ?? [];
$_SERVER['APP_RUNTIME_OPTIONS'] ??= [];
$_SERVER['APP_RUNTIME_OPTIONS'] += [
'project_dir' => __DIR__,
] + ($_SERVER['APP_RUNTIME_OPTIONS'] ?? []);
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/LazyString.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function fromCallable(callable|array $callback, mixed ...$argument
if (null !== $arguments) {
if (!\is_callable($callback)) {
$callback[0] = $callback[0]();
$callback[1] = $callback[1] ?? '__invoke';
$callback[1] ??= '__invoke';
}
$value = $callback(...$arguments);
$callback = self::getPrettyName($callback);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Validator/Constraints/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ private function normalizeBinaryFormat(int|string $maxSize)
];
if (ctype_digit((string) $maxSize)) {
$this->maxSize = (int) $maxSize;
$this->binaryFormat = $this->binaryFormat ?? false;
$this->binaryFormat ??= false;
} elseif (preg_match('/^(\d++)('.implode('|', array_keys($factors)).')$/i', $maxSize, $matches)) {
$this->maxSize = $matches[1] * $factors[$unit = strtolower($matches[2])];
$this->binaryFormat = $this->binaryFormat ?? (2 === \strlen($unit));
$this->binaryFormat ??= 2 === \strlen($unit);
} else {
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum size.', $maxSize));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/VarDumper/Caster/MemcachedCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static function castMemcached(\Memcached $c, array $a, Stub $stub, bool $

private static function getNonDefaultOptions(\Memcached $c): array
{
self::$defaultOptions = self::$defaultOptions ?? self::discoverDefaultOptions();
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
self::$defaultOptions ??= self::discoverDefaultOptions();
self::$optionConstants ??= self::getOptionConstants();

$nonDefaultOptions = [];
foreach (self::$optionConstants as $constantKey => $value) {
Expand All @@ -56,7 +56,7 @@ private static function discoverDefaultOptions(): array
$defaultMemcached->addServer('127.0.0.1', 11211);

$defaultOptions = [];
self::$optionConstants = self::$optionConstants ?? self::getOptionConstants();
self::$optionConstants ??= self::getOptionConstants();

foreach (self::$optionConstants as $constantKey => $value) {
$defaultOptions[$constantKey] = $defaultMemcached->getOption($value);
Expand Down
0