From 22a6f7b1bd01fce581c2606bc87b1dacb0212350 Mon Sep 17 00:00:00 2001 From: Roland Franssen Date: Tue, 30 Apr 2019 20:16:19 +0200 Subject: [PATCH] [Intl] Add phpdoc --- src/Symfony/Component/Intl/Currencies.php | 12 +++++++++ src/Symfony/Component/Intl/Languages.php | 3 +++ src/Symfony/Component/Intl/Locales.php | 3 +++ src/Symfony/Component/Intl/Regions.php | 3 +++ src/Symfony/Component/Intl/Scripts.php | 3 +++ .../Component/Intl/Tests/CurrenciesTest.php | 5 +++- .../Component/Intl/Tests/ScriptsTest.php | 1 + .../Component/Intl/Tests/TimezonesTest.php | 26 ++++++++++++++++--- src/Symfony/Component/Intl/Timezones.php | 13 ++++++++++ 9 files changed, 64 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Intl/Currencies.php b/src/Symfony/Component/Intl/Currencies.php index 5d6a4b06cce63..7459d633cba9e 100644 --- a/src/Symfony/Component/Intl/Currencies.php +++ b/src/Symfony/Component/Intl/Currencies.php @@ -45,6 +45,9 @@ public static function exists(string $currency): bool } } + /** + * @throws MissingResourceException if the currency code does not exists + */ public static function getName(string $currency, string $displayLocale = null): string { return self::readEntry(['Names', $currency, self::INDEX_NAME], $displayLocale); @@ -74,6 +77,9 @@ public static function getNames(string $displayLocale = null): array return self::asort($names, $displayLocale); } + /** + * @throws MissingResourceException if the currency code does not exists + */ public static function getSymbol(string $currency, string $displayLocale = null): string { return self::readEntry(['Names', $currency, self::INDEX_SYMBOL], $displayLocale); @@ -100,11 +106,17 @@ public static function getRoundingIncrement(string $currency) } } + /** + * @throws MissingResourceException if the currency code has no numeric code + */ public static function getNumericCode(string $currency): int { return self::readEntry(['Alpha3ToNumeric', $currency], 'meta'); } + /** + * @throws MissingResourceException if the numeric code does not exists + */ public static function forNumericCode(int $numericCode): array { return self::readEntry(['NumericToAlpha3', (string) $numericCode], 'meta'); diff --git a/src/Symfony/Component/Intl/Languages.php b/src/Symfony/Component/Intl/Languages.php index 64d85a6ade3ec..127f15f3e8aa8 100644 --- a/src/Symfony/Component/Intl/Languages.php +++ b/src/Symfony/Component/Intl/Languages.php @@ -49,6 +49,9 @@ public static function exists(string $language): bool } } + /** + * @throws MissingResourceException if the language code does not exists + */ public static function getName(string $language, string $displayLocale = null): string { return self::readEntry(['Names', $language], $displayLocale); diff --git a/src/Symfony/Component/Intl/Locales.php b/src/Symfony/Component/Intl/Locales.php index 980c8f8b6b679..c5def031cf47b 100644 --- a/src/Symfony/Component/Intl/Locales.php +++ b/src/Symfony/Component/Intl/Locales.php @@ -48,6 +48,9 @@ public static function exists(string $locale): bool } } + /** + * @throws MissingResourceException if the locale does not exists + */ public static function getName(string $locale, string $displayLocale = null): string { return self::readEntry(['Names', $locale], $displayLocale); diff --git a/src/Symfony/Component/Intl/Regions.php b/src/Symfony/Component/Intl/Regions.php index b3606c0b30197..a0b7dbacff354 100644 --- a/src/Symfony/Component/Intl/Regions.php +++ b/src/Symfony/Component/Intl/Regions.php @@ -40,6 +40,9 @@ public static function exists(string $region): bool } } + /** + * @throws MissingResourceException if the region code does not exists + */ public static function getName(string $region, string $displayLocale = null): string { return self::readEntry(['Names', $region], $displayLocale); diff --git a/src/Symfony/Component/Intl/Scripts.php b/src/Symfony/Component/Intl/Scripts.php index b01ff848efb97..bf26969c06550 100644 --- a/src/Symfony/Component/Intl/Scripts.php +++ b/src/Symfony/Component/Intl/Scripts.php @@ -40,6 +40,9 @@ public static function exists(string $script): bool } } + /** + * @throws MissingResourceException if the script code does not exists + */ public static function getName(string $script, string $displayLocale = null): string { return self::readEntry(['Names', $script], $displayLocale); diff --git a/src/Symfony/Component/Intl/Tests/CurrenciesTest.php b/src/Symfony/Component/Intl/Tests/CurrenciesTest.php index dff4c157cda81..86e5f377f18e4 100644 --- a/src/Symfony/Component/Intl/Tests/CurrenciesTest.php +++ b/src/Symfony/Component/Intl/Tests/CurrenciesTest.php @@ -683,7 +683,10 @@ function ($currency) { return [$currency]; }, */ public function testGetFractionDigits($currency) { - $this->assertInternalType('numeric', Currencies::getFractionDigits($currency)); + // ensure each currency code has a corresponding fraction digit + Currencies::getFractionDigits($currency); + + $this->addToAssertionCount(1); } /** diff --git a/src/Symfony/Component/Intl/Tests/ScriptsTest.php b/src/Symfony/Component/Intl/Tests/ScriptsTest.php index 71ca1a0031374..1149abb1b86f8 100644 --- a/src/Symfony/Component/Intl/Tests/ScriptsTest.php +++ b/src/Symfony/Component/Intl/Tests/ScriptsTest.php @@ -287,5 +287,6 @@ public function testExists() { $this->assertTrue(Scripts::exists('Hans')); $this->assertTrue(Scripts::exists('Zzzz')); + $this->assertFalse(Scripts::exists('foobar')); } } diff --git a/src/Symfony/Component/Intl/Tests/TimezonesTest.php b/src/Symfony/Component/Intl/Tests/TimezonesTest.php index 61f4e6765a481..793da9a8b3162 100644 --- a/src/Symfony/Component/Intl/Tests/TimezonesTest.php +++ b/src/Symfony/Component/Intl/Tests/TimezonesTest.php @@ -549,6 +549,15 @@ public function testGetRawOffset() $this->assertSame(20700, Timezones::getRawOffset('Asia/Katmandu')); } + /** + * @expectedException \Exception + * @expectedExceptionMessage Unknown or bad timezone (foobar) + */ + public function testGetRawOffsetWithUnknownTimezone() + { + Timezones::getRawOffset('foobar'); + } + public function testGetGmtOffset() { // timezones free from DST changes to avoid time-based variance @@ -595,8 +604,11 @@ public function testGetCountryCodeWithUnknownTimezone() */ public function testGetGmtOffsetAvailability(string $timezone) { - $this->assertInternalType('int', Timezones::getRawOffset($timezone)); - $this->assertInternalType('string', Timezones::getGmtOffset($timezone)); + // ensure each timezone identifier has a corresponding GMT offset + Timezones::getRawOffset($timezone); + Timezones::getGmtOffset($timezone); + + $this->addToAssertionCount(1); } /** @@ -605,7 +617,10 @@ public function testGetGmtOffsetAvailability(string $timezone) public function testGetCountryCodeAvailability(string $timezone) { try { - $this->assertInternalType('string', Timezones::getCountryCode($timezone)); + // ensure each timezone identifier has a corresponding country code + Timezones::getCountryCode($timezone); + + $this->addToAssertionCount(1); } catch (MissingResourceException $e) { if (\in_array($timezone, self::$zonesNoCountry, true)) { $this->markTestSkipped(); @@ -627,7 +642,10 @@ public function provideTimezones(): iterable */ public function testForCountryCodeAvailability(string $country) { - $this->assertInternalType('array', Timezones::forCountryCode($country)); + // ensure each country code has a list of timezone identifiers (possibly empty) + Timezones::forCountryCode($country); + + $this->addToAssertionCount(1); } public function provideCountries(): iterable diff --git a/src/Symfony/Component/Intl/Timezones.php b/src/Symfony/Component/Intl/Timezones.php index 94b8b27e301f7..05a44c94ac489 100644 --- a/src/Symfony/Component/Intl/Timezones.php +++ b/src/Symfony/Component/Intl/Timezones.php @@ -40,6 +40,9 @@ public static function exists(string $timezone): bool } } + /** + * @throws MissingResourceException if the timezone identifier does not exists + */ public static function getName(string $timezone, string $displayLocale = null): string { return self::readEntry(['Names', $timezone], $displayLocale); @@ -53,6 +56,10 @@ public static function getNames(string $displayLocale = null): array return self::asort(self::readEntry(['Names'], $displayLocale), $displayLocale); } + /** + * @throws \Exception if the timezone identifier does not exists + * @throws RuntimeException if there's no timezone DST transition information available + */ public static function getRawOffset(string $timezone, int $timestamp = null): int { if (null === $timestamp) { @@ -76,11 +83,17 @@ public static function getGmtOffset(string $timezone, int $timestamp = null, str return sprintf(self::readEntry(['Meta', 'GmtFormat'], $displayLocale), sprintf(self::readEntry(['Meta', 'HourFormat', 0 <= $offset ? 0 : 1], $displayLocale), $abs / 3600, $abs / 60 % 60)); } + /** + * @throws MissingResourceException if the timezone identifier has no associated country code + */ public static function getCountryCode(string $timezone): string { return self::readEntry(['ZoneToCountry', $timezone], 'meta'); } + /** + * @throws MissingResourceException if the country code does not exists + */ public static function forCountryCode(string $country): array { try {