From b1c754f04be10cc908f7efc3fdabcda7573fd8cf Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Thu, 9 Feb 2023 23:12:22 -0800 Subject: [PATCH] Correct Some Scrutinizer Messages (#3354) They have crept in recently. --- .../Style/NumberFormat/Wizard/Accounting.php | 3 ++- src/PhpSpreadsheet/Style/NumberFormat/Wizard/Currency.php | 2 +- src/PhpSpreadsheet/Style/NumberFormat/Wizard/Locale.php | 4 ++-- .../Style/NumberFormat/Wizard/NumberBase.php | 2 +- .../Style/NumberFormat/Wizard/Percentage.php | 2 +- .../Style/NumberFormat/Wizard/AccountingTest.php | 8 ++++---- .../Style/NumberFormat/Wizard/CurrencyTest.php | 8 ++++---- .../Style/NumberFormat/Wizard/NumberTest.php | 4 ++-- .../Style/NumberFormat/Wizard/PercentageTest.php | 8 ++++---- .../Style/NumberFormat/Wizard/ScientificTest.php | 4 ++-- 10 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Accounting.php b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Accounting.php index 3e23bedf9..a726b1537 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Accounting.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Accounting.php @@ -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()); } diff --git a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Currency.php b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Currency.php index b25bbfd87..957015408 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Currency.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Currency.php @@ -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()); } diff --git a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Locale.php b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Locale.php index 2253e8120..9f0336274 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Locale.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Locale.php @@ -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}'"); diff --git a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/NumberBase.php b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/NumberBase.php index 051b7f437..73ab570f5 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/NumberBase.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/NumberBase.php @@ -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); } diff --git a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Percentage.php b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Percentage.php index 19cc702b5..003c0ddf1 100644 --- a/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Percentage.php +++ b/src/PhpSpreadsheet/Style/NumberFormat/Wizard/Percentage.php @@ -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()) diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/AccountingTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/AccountingTest.php index 6513a891d..59494f341 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/AccountingTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/AccountingTest.php @@ -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); diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/CurrencyTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/CurrencyTest.php index 6647628a5..b31ccc029 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/CurrencyTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/CurrencyTest.php @@ -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); diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/NumberTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/NumberTest.php index 28189f1f4..1ff2a599b 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/NumberTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/NumberTest.php @@ -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); diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/PercentageTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/PercentageTest.php index e29fd1e1c..93112c759 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/PercentageTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/PercentageTest.php @@ -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); diff --git a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/ScientificTest.php b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/ScientificTest.php index d32c2380b..9e1a5f631 100644 --- a/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/ScientificTest.php +++ b/tests/PhpSpreadsheetTests/Style/NumberFormat/Wizard/ScientificTest.php @@ -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);