Skip to content

Commit 2d58e64

Browse files
committed
[l18n] improvement: use null coalescing operator
1 parent 9e76cb9 commit 2d58e64

File tree

4 files changed

+5
-23
lines changed

4 files changed

+5
-23
lines changed

lib/i18n/sfCultureInfo.class.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,7 @@ public function getCountry($code)
470470
{
471471
$countries = $this->findInfo('Countries', true);
472472

473-
if (!isset($countries[$code])) {
474-
throw new InvalidArgumentException(sprintf('The country %s does not exist.', $code));
475-
}
476-
477-
return $countries[$code];
473+
return $countries[$code] ?? throw new InvalidArgumentException(sprintf('The country %s does not exist.', $code));;
478474
}
479475

480476
/**
@@ -488,11 +484,7 @@ public function getCurrency($code)
488484
{
489485
$currencies = $this->findInfo('Currencies', true);
490486

491-
if (!isset($currencies[$code])) {
492-
throw new InvalidArgumentException(sprintf('The currency %s does not exist.', $code));
493-
}
494-
495-
return $currencies[$code][1];
487+
return $currencies[$code][1] ?? throw new InvalidArgumentException(sprintf('The currency %s does not exist.', $code));
496488
}
497489

498490
/**

lib/i18n/sfDateFormat.class.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,7 @@ public function getInputPattern($pattern)
381381
*/
382382
protected function getFunctionName($token)
383383
{
384-
if (isset($this->tokens[$token[0]])) {
385-
return $this->tokens[$token[0]];
386-
}
384+
return $this->tokens[$token[0]] ?? null;
387385
}
388386

389387
/**

lib/i18n/sfDateTimeFormatInfo.class.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,7 @@ public function setNarrowMonthNames($value)
284284
*/
285285
public function getAbbreviatedMonthNames()
286286
{
287-
if (isset($this->data['monthNames']['format']['abbreviated'])) {
288-
return $this->data['monthNames']['format']['abbreviated'];
289-
}
290-
291-
return $this->data['monthNames']['format']['wide'];
287+
return $this->data['monthNames']['format']['abbreviated'] ?? $this->data['monthNames']['format']['wide'];
292288
}
293289

294290
/**

lib/i18n/sfNumberFormatInfo.class.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,11 +409,7 @@ public function setPositivePattern($pattern)
409409
*/
410410
public function getCurrencySymbol($currency = 'USD')
411411
{
412-
if (isset($this->pattern['symbol'])) {
413-
return $this->pattern['symbol'];
414-
}
415-
416-
return $this->data['Currencies'][$currency][0];
412+
return $this->pattern['symbol'] ?? $this->data['Currencies'][$currency][0];
417413
}
418414

419415
/**

0 commit comments

Comments
 (0)