mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-30 03:59:11 +00:00
@@ -51,7 +51,8 @@ class Accounting extends Currency
|
||||
throw new Exception('The Intl extension does not support Accounting Formats without ICU 53');
|
||||
}
|
||||
|
||||
$formatter = new Locale($this->fullLocale, NumberFormatter::CURRENCY_ACCOUNTING); // @phpstan-ignore-line
|
||||
// Scrutinizer does not recognize CURRENCY_ACCOUNTING
|
||||
$formatter = new Locale($this->fullLocale, NumberFormatter::CURRENCY_ACCOUNTING);
|
||||
|
||||
return str_replace('¤', $this->formatCurrencyCode(), $formatter->format());
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class Currency extends Number
|
||||
|
||||
protected function getLocaleFormat(): string
|
||||
{
|
||||
$formatter = new Locale($this->fullLocale, NumberFormatter::CURRENCY); // @phpstan-ignore-line
|
||||
$formatter = new Locale($this->fullLocale, NumberFormatter::CURRENCY);
|
||||
|
||||
return str_replace('¤', $this->formatCurrencyCode(), $formatter->format());
|
||||
}
|
||||
|
||||
@@ -17,13 +17,13 @@ final class Locale
|
||||
|
||||
private NumberFormatter $formatter;
|
||||
|
||||
public function __construct(string $locale, int $style)
|
||||
public function __construct(?string $locale, int $style)
|
||||
{
|
||||
if (class_exists(NumberFormatter::class) === false) {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
$formatterLocale = str_replace('-', '_', $locale);
|
||||
$formatterLocale = str_replace('-', '_', $locale ?? '');
|
||||
$this->formatter = new NumberFormatter($formatterLocale, $style);
|
||||
if ($this->formatter->getLocale() !== $formatterLocale) {
|
||||
throw new Exception("Unable to read locale data for '{$locale}'");
|
||||
|
||||
@@ -18,7 +18,7 @@ abstract class NumberBase
|
||||
|
||||
protected ?string $localeFormat = null;
|
||||
|
||||
public function setDecimals(int $decimals = 2, ?string $locale = null): void
|
||||
public function setDecimals(int $decimals = 2): void
|
||||
{
|
||||
$this->decimals = ($decimals > self::MAX_DECIMALS) ? self::MAX_DECIMALS : max($decimals, 0);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class Percentage extends NumberBase implements Wizard
|
||||
|
||||
protected function getLocaleFormat(): string
|
||||
{
|
||||
$formatter = new Locale($this->fullLocale, NumberFormatter::PERCENT); // @phpstan-ignore-line
|
||||
$formatter = new Locale($this->fullLocale, NumberFormatter::PERCENT);
|
||||
|
||||
return $this->decimals > 0
|
||||
? str_replace('0', '0.' . str_repeat('0', $this->decimals), $formatter->format())
|
||||
|
||||
@@ -78,8 +78,8 @@ class AccountingTest extends TestCase
|
||||
|
||||
$locale = 'en-usa';
|
||||
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
|
||||
$wizard = new Accounting('€');
|
||||
$wizard->setLocale($locale);
|
||||
@@ -93,8 +93,8 @@ class AccountingTest extends TestCase
|
||||
|
||||
$locale = 'nl-GB';
|
||||
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionMessage("Unable to read locale data for '{$locale}'");
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Unable to read locale data for '{$locale}'");
|
||||
|
||||
$wizard = new Accounting('€');
|
||||
$wizard->setLocale($locale);
|
||||
|
||||
@@ -77,8 +77,8 @@ class CurrencyTest extends TestCase
|
||||
|
||||
$locale = 'en-usa';
|
||||
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
|
||||
$wizard = new Currency('€');
|
||||
$wizard->setLocale($locale);
|
||||
@@ -92,8 +92,8 @@ class CurrencyTest extends TestCase
|
||||
|
||||
$locale = 'nl-GB';
|
||||
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionMessage("Unable to read locale data for '{$locale}'");
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Unable to read locale data for '{$locale}'");
|
||||
|
||||
$wizard = new Currency('€');
|
||||
$wizard->setLocale($locale);
|
||||
|
||||
@@ -61,8 +61,8 @@ class NumberTest extends TestCase
|
||||
|
||||
$locale = 'en-usa';
|
||||
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
|
||||
$wizard = new Number(2);
|
||||
$wizard->setLocale($locale);
|
||||
|
||||
@@ -67,8 +67,8 @@ class PercentageTest extends TestCase
|
||||
|
||||
$locale = 'en-usa';
|
||||
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
|
||||
$wizard = new Percentage(2);
|
||||
$wizard->setLocale($locale);
|
||||
@@ -82,8 +82,8 @@ class PercentageTest extends TestCase
|
||||
|
||||
$locale = 'nl-GB';
|
||||
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionMessage("Unable to read locale data for '{$locale}'");
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Unable to read locale data for '{$locale}'");
|
||||
|
||||
$wizard = new Percentage(2);
|
||||
$wizard->setLocale($locale);
|
||||
|
||||
@@ -66,8 +66,8 @@ class ScientificTest extends TestCase
|
||||
|
||||
$locale = 'en-usa';
|
||||
|
||||
self::expectException(Exception::class);
|
||||
self::expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
$this->expectException(Exception::class);
|
||||
$this->expectExceptionMessage("Invalid locale code '{$locale}'");
|
||||
|
||||
$wizard = new Scientific(2);
|
||||
$wizard->setLocale($locale);
|
||||
|
||||
Reference in New Issue
Block a user