Skip to content

[Intl][5.0] Add parameters type-hints #32525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Symfony/Component/Intl/Collator/Collator.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct(?string $locale)
*
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
*/
public static function create($locale)
public static function create(?string $locale)
{
return new self($locale);
}
Expand All @@ -106,7 +106,7 @@ public static function create($locale)
*
* @return bool True on success or false on failure
*/
public function asort(&$array, $sortFlag = self::SORT_REGULAR)
public function asort(array &$array, int $sortFlag = self::SORT_REGULAR)
{
$intlToPlainFlagMap = [
self::SORT_REGULAR => \SORT_REGULAR,
Expand Down Expand Up @@ -134,7 +134,7 @@ public function asort(&$array, $sortFlag = self::SORT_REGULAR)
*
* @throws MethodNotImplementedException
*/
public function compare($str1, $str2)
public function compare(string $str1, string $str2)
{
throw new MethodNotImplementedException(__METHOD__);
}
Expand All @@ -150,7 +150,7 @@ public function compare($str1, $str2)
*
* @throws MethodNotImplementedException
*/
public function getAttribute($attr)
public function getAttribute(int $attr)
{
throw new MethodNotImplementedException(__METHOD__);
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public function getErrorMessage()
* @return string The locale used to create the collator. Currently always
* returns "en".
*/
public function getLocale($type = Locale::ACTUAL_LOCALE)
public function getLocale(int $type = Locale::ACTUAL_LOCALE)
{
return 'en';
}
Expand All @@ -199,7 +199,7 @@ public function getLocale($type = Locale::ACTUAL_LOCALE)
*
* @throws MethodNotImplementedException
*/
public function getSortKey($string)
public function getSortKey(string $string)
{
throw new MethodNotImplementedException(__METHOD__);
}
Expand Down Expand Up @@ -230,7 +230,7 @@ public function getStrength()
*
* @throws MethodNotImplementedException
*/
public function setAttribute($attr, $val)
public function setAttribute(int $attr, int $val)
{
throw new MethodNotImplementedException(__METHOD__);
}
Expand All @@ -252,7 +252,7 @@ public function setAttribute($attr, $val)
*
* @throws MethodNotImplementedException
*/
public function setStrength($strength)
public function setStrength(int $strength)
{
throw new MethodNotImplementedException(__METHOD__);
}
Expand All @@ -268,7 +268,7 @@ public function setStrength($strength)
*
* @throws MethodNotImplementedException
*/
public function sortWithSortKeys(&$arr)
public function sortWithSortKeys(array &$arr)
{
throw new MethodNotImplementedException(__METHOD__);
}
Expand All @@ -288,7 +288,7 @@ public function sortWithSortKeys(&$arr)
*
* @throws MethodNotImplementedException
*/
public function sort(&$arr, $sortFlag = self::SORT_REGULAR)
public function sort(array &$arr, int $sortFlag = self::SORT_REGULAR)
{
throw new MethodNotImplementedException(__METHOD__);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ interface BundleCompilerInterface
/**
* Compiles a resource bundle at the given source to the given target
* directory.
*
* @param string $sourcePath
* @param string $targetDir
*/
public function compile($sourcePath, $targetDir);
public function compile(string $sourcePath, string $targetDir);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(string $genrb = 'genrb', string $envVars = '')
/**
* {@inheritdoc}
*/
public function compile($sourcePath, $targetDir)
public function compile(string $sourcePath, string $targetDir)
{
if (is_dir($sourcePath)) {
$sourcePath .= '/*.txt';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(BundleReaderInterface $reader, int $bufferSize)
/**
* {@inheritdoc}
*/
public function read($path, $locale)
public function read(string $path, string $locale)
{
$hash = $path.'//'.$locale;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ public function __construct(BundleReaderInterface $reader)
*
* @param array $localeAliases A mapping of locale aliases to locales
*/
public function setLocaleAliases($localeAliases)
public function setLocaleAliases(array $localeAliases)
{
$this->localeAliases = $localeAliases;
}

/**
* {@inheritdoc}
*/
public function read($path, $locale)
public function read(string $path, string $locale)
{
return $this->reader->read($path, $locale);
}

/**
* {@inheritdoc}
*/
public function readEntry($path, $locale, array $indices, $fallback = true)
public function readEntry(string $path, string $locale, array $indices, bool $fallback = true)
{
$entry = null;
$isMultiValued = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface BundleEntryReaderInterface extends BundleReaderInterface
* $reader->readEntry('...', 'en', ['TopLevel', 'NestedLevel', 'Entry']);
*
* @param string $path The path to the resource bundle
* @param string $locale The locale to read
* @param string[] $indices The indices to read from the bundle
* @param bool $fallback Whether to merge the value with the value from
* the fallback locale (e.g. "en" for "en_GB").
Expand All @@ -51,5 +50,5 @@ interface BundleEntryReaderInterface extends BundleReaderInterface
*
* @throws MissingResourceException If the indices cannot be accessed
*/
public function readEntry($path, $locale, array $indices, $fallback = true);
public function readEntry(string $path, string $locale, array $indices, bool $fallback = true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@
interface BundleReaderInterface
{
/**
* Reads a resource bundle.
*
* @param string $path The path to the resource bundle
* @param string $locale The locale to read
*
* @return mixed returns an array or {@link \ArrayAccess} instance for
* complex data, a scalar value otherwise
*/
public function read($path, $locale);
public function read(string $path, string $locale);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IntlBundleReader implements BundleReaderInterface
/**
* {@inheritdoc}
*/
public function read($path, $locale)
public function read(string $path, string $locale)
{
// Point for future extension: Modify this class so that it works also
// if the \ResourceBundle class is not available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JsonBundleReader implements BundleReaderInterface
/**
* {@inheritdoc}
*/
public function read($path, $locale)
public function read(string $path, string $locale)
{
$fileName = $path.'/'.$locale.'.json';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PhpBundleReader implements BundleReaderInterface
/**
* {@inheritdoc}
*/
public function read($path, $locale)
public function read(string $path, string $locale)
{
$fileName = $path.'/'.$locale.'.php';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ interface BundleWriterInterface
/**
* Writes data to a resource bundle.
*
* @param string $path The path to the resource bundle
* @param string $locale The locale to (over-)write
* @param mixed $data The data to write
* @param mixed $data The data to write
*/
public function write($path, $locale, $data);
public function write(string $path, string $locale, $data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class JsonBundleWriter implements BundleWriterInterface
/**
* {@inheritdoc}
*/
public function write($path, $locale, $data)
public function write(string $path, string $locale, $data)
{
if ($data instanceof \Traversable) {
$data = iterator_to_array($data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PhpBundleWriter implements BundleWriterInterface
/**
* {@inheritdoc}
*/
public function write($path, $locale, $data)
public function write(string $path, string $locale, $data)
{
$template = <<<'TEMPLATE'
<?php
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TextBundleWriter implements BundleWriterInterface
/**
* {@inheritdoc}
*/
public function write($path, $locale, $data, $fallback = true)
public function write(string $path, string $locale, $data, bool $fallback = true)
{
$file = fopen($path.'/'.$locale.'.txt', 'w');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,26 @@ public function generateData(GeneratorConfig $config)
}

/**
* @param string $sourceDir
*
* @return string[]
*/
abstract protected function scanLocales(LocaleScanner $scanner, $sourceDir);
abstract protected function scanLocales(LocaleScanner $scanner, string $sourceDir);

/**
* @param string $sourceDir
* @param string $tempDir
*/
abstract protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir);
abstract protected function compileTemporaryBundles(BundleCompilerInterface $compiler, string $sourceDir, string $tempDir);

abstract protected function preGenerate();

/**
* @param string $tempDir
* @param string $displayLocale
*
* @return array|null
*/
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale);
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale);

/**
* @param string $tempDir
*
* @return array|null
*/
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir);
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, string $tempDir);

/**
* @param string $tempDir
*
* @return array|null
*/
abstract protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir);
abstract protected function generateDataForMeta(BundleEntryReaderInterface $reader, string $tempDir);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class CurrencyDataGenerator extends AbstractDataGenerator
/**
* {@inheritdoc}
*/
protected function scanLocales(LocaleScanner $scanner, $sourceDir)
protected function scanLocales(LocaleScanner $scanner, string $sourceDir)
{
return $scanner->scanLocales($sourceDir.'/curr');
}

/**
* {@inheritdoc}
*/
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir)
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, string $sourceDir, string $tempDir)
{
$compiler->compile($sourceDir.'/curr', $tempDir);
$compiler->compile($sourceDir.'/misc/currencyNumericCodes.txt', $tempDir);
Expand All @@ -76,7 +76,7 @@ protected function preGenerate()
/**
* {@inheritdoc}
*/
protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale)
protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale)
{
$localeBundle = $reader->read($tempDir, $displayLocale);

Expand All @@ -95,7 +95,7 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, $te
/**
* {@inheritdoc}
*/
protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir)
protected function generateDataForRoot(BundleEntryReaderInterface $reader, string $tempDir)
{
$rootBundle = $reader->read($tempDir, 'root');

Expand All @@ -108,7 +108,7 @@ protected function generateDataForRoot(BundleEntryReaderInterface $reader, $temp
/**
* {@inheritdoc}
*/
protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir)
protected function generateDataForMeta(BundleEntryReaderInterface $reader, string $tempDir)
{
$rootBundle = $reader->read($tempDir, 'root');
$supplementalDataBundle = $reader->read($tempDir, 'supplementalData');
Expand Down
9 changes: 2 additions & 7 deletions src/Symfony/Component/Intl/Data/Generator/FallbackTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@ trait FallbackTrait
private $generatingFallback = false;

/**
* @param string $tempDir
* @param string $displayLocale
*
* @return array|null
*
* @see AbstractDataGenerator::generateDataForLocale()
*/
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale);
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale);

/**
* @param string $tempDir
*
* @return array|null
*
* @see AbstractDataGenerator::generateDataForRoot()
*/
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir);
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, string $tempDir);

private function generateFallbackData(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public function __construct(string $sourceDir, string $icuVersion)

/**
* Adds a writer to be used during the data conversion.
*
* @param string $targetDir The output directory
*/
public function addBundleWriter($targetDir, BundleWriterInterface $writer)
public function addBundleWriter(string $targetDir, BundleWriterInterface $writer)
{
$this->bundleWriters[$targetDir] = $writer;
}
Expand Down
Loading