[Intl] Add phpdoc

This commit is contained in:
Roland Franssen 2019-04-30 20:16:19 +02:00 committed by Fabien Potencier
parent 1c110fa1f7
commit 22a6f7b1bd
9 changed files with 64 additions and 5 deletions

View File

@ -45,6 +45,9 @@ final class Currencies extends ResourceBundle
}
}
/**
* @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 @@ final class Currencies extends ResourceBundle
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 @@ final class Currencies extends ResourceBundle
}
}
/**
* @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');

View File

@ -49,6 +49,9 @@ final class Languages extends ResourceBundle
}
}
/**
* @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);

View File

@ -48,6 +48,9 @@ final class Locales extends ResourceBundle
}
}
/**
* @throws MissingResourceException if the locale does not exists
*/
public static function getName(string $locale, string $displayLocale = null): string
{
return self::readEntry(['Names', $locale], $displayLocale);

View File

@ -40,6 +40,9 @@ final class Regions extends ResourceBundle
}
}
/**
* @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);

View File

@ -40,6 +40,9 @@ final class Scripts extends ResourceBundle
}
}
/**
* @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);

View File

@ -683,7 +683,10 @@ class CurrenciesTest extends ResourceBundleTestCase
*/
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);
}
/**

View File

@ -287,5 +287,6 @@ class ScriptsTest extends ResourceBundleTestCase
{
$this->assertTrue(Scripts::exists('Hans'));
$this->assertTrue(Scripts::exists('Zzzz'));
$this->assertFalse(Scripts::exists('foobar'));
}
}

View File

@ -549,6 +549,15 @@ class TimezonesTest extends ResourceBundleTestCase
$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 @@ class TimezonesTest extends ResourceBundleTestCase
*/
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 @@ class TimezonesTest extends ResourceBundleTestCase
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 @@ class TimezonesTest extends ResourceBundleTestCase
*/
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

View File

@ -40,6 +40,9 @@ final class Timezones extends ResourceBundle
}
}
/**
* @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 @@ final class Timezones extends ResourceBundle
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 @@ final class Timezones extends ResourceBundle
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 {