Skip to content

Commit

Permalink
[Intl] Add phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ro0NL authored and fabpot committed May 1, 2019
1 parent 1c110fa commit 22a6f7b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/Symfony/Component/Intl/Currencies.php
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Intl/Languages.php
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Intl/Locales.php
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Intl/Regions.php
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Intl/Scripts.php
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Component/Intl/Tests/CurrenciesTest.php
Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Intl/Tests/ScriptsTest.php
Expand Up @@ -287,5 +287,6 @@ public function testExists()
{
$this->assertTrue(Scripts::exists('Hans'));
$this->assertTrue(Scripts::exists('Zzzz'));
$this->assertFalse(Scripts::exists('foobar'));
}
}
26 changes: 22 additions & 4 deletions src/Symfony/Component/Intl/Tests/TimezonesTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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();
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Intl/Timezones.php
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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 {
Expand Down

0 comments on commit 22a6f7b

Please sign in to comment.