Skip to content

Commit

Permalink
Use ??= more
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 2, 2022
1 parent 261d195 commit c08de62
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 20 deletions.
4 changes: 1 addition & 3 deletions DataCollectorTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ public function getCollectedMessages(): array

private function collectMessage(?string $locale, ?string $domain, string $id, string $translation, ?array $parameters = [])
{
if (null === $domain) {
$domain = 'messages';
}
$domain ??= 'messages';

$catalogue = $this->translator->getCatalogue($locale);
$locale = $catalogue->getLocale();
Expand Down
4 changes: 1 addition & 3 deletions Loader/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ public function load(mixed $resource, string $locale, string $domain = 'messages
$messages = $this->loadResource($resource);

// empty resource
if (null === $messages) {
$messages = [];
}
$messages ??= [];

// not an array
if (!\is_array($messages)) {
Expand Down
4 changes: 1 addition & 3 deletions LoggingTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ public function __call(string $method, array $args)
*/
private function log(string $id, ?string $domain, ?string $locale)
{
if (null === $domain) {
$domain = 'messages';
}
$domain ??= 'messages';

$catalogue = $this->translator->getCatalogue($locale);
if ($catalogue->defines($id, $domain)) {
Expand Down
14 changes: 3 additions & 11 deletions Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,7 @@ public function __construct(string $locale, MessageFormatterInterface $formatter
{
$this->setLocale($locale);

if (null === $formatter) {
$formatter = new MessageFormatter();
}

$this->formatter = $formatter;
$this->formatter = $formatter ??= new MessageFormatter();
$this->cacheDir = $cacheDir;
$this->debug = $debug;
$this->cacheVary = $cacheVary;
Expand Down Expand Up @@ -109,9 +105,7 @@ public function addLoader(string $format, LoaderInterface $loader)
*/
public function addResource(string $format, mixed $resource, string $locale, string $domain = null)
{
if (null === $domain) {
$domain = 'messages';
}
$domain ??= 'messages';

$this->assertValidLocale($locale);
$locale ?: $locale = class_exists(\Locale::class) ? \Locale::getDefault() : 'en';
Expand Down Expand Up @@ -171,9 +165,7 @@ public function trans(?string $id, array $parameters = [], string $domain = null
return '';
}

if (null === $domain) {
$domain = 'messages';
}
$domain ??= 'messages';

$catalogue = $this->getCatalogue($locale);
$locale = $catalogue->getLocale();
Expand Down

0 comments on commit c08de62

Please sign in to comment.