10000 [Intl][5.0] Add parameters type-hints · symfony/symfony@ce79f4b · GitHub
[go: up one dir, main page]

Skip to content

Commit ce79f4b

Browse files
Philippe Segatorinicolas-grekas
Philippe Segatori
authored andcommitted
[Intl][5.0] Add parameters type-hints
1 parent f6c5848 commit ce79f4b

38 files changed

+155
-207
lines changed

src/Symfony/Component/Intl/Collator/Collator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function __construct(?string $locale)
9090
*
9191
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
9292
*/
93-
public static function create($locale)
93+
public static function create(?string $locale)
9494
{
9595
return new self($locale);
9696
}
@@ -106,7 +106,7 @@ public static function create($locale)
106106
*
107107
* @return bool True on success or false on failure
108108
*/
109-
public function asort(&$array, $sortFlag = self::SORT_REGULAR)
109+
public function asort(array &$array, int $sortFlag = self::SORT_REGULAR)
110110
{
111111
$intlToPlainFlagMap = [
112112
self::SORT_REGULAR => \SORT_REGULAR,
@@ -134,7 +134,7 @@ public function asort(&$array, $sortFlag = self::SORT_REGULAR)
134134
*
135135
* @throws MethodNotImplementedException
136136
*/
137-
public function compare($str1, $str2)
137+
public function compare(string $str1, string $str2)
138138
{
139139
throw new MethodNotImplementedException(__METHOD__);
140140
}
@@ -150,7 +150,7 @@ public function compare($str1, $str2)
150150
*
151151
* @throws MethodNotImplementedException
152152
*/
153-
public function getAttribute($attr)
153+
public function getAttribute(int $attr)
154154
{
155155
throw new MethodNotImplementedException(__METHOD__);
156156
}
@@ -183,7 +183,7 @@ public function getErrorMessage()
183183
* @return string The locale used to create the collator. Currently always
184184
* returns "en".
185185
*/
186-
public function getLocale($type = Locale::ACTUAL_LOCALE)
186+
public function getLocale(int $type = Locale::ACTUAL_LOCALE)
187187
{
188188
return 'en';
189189
}
@@ -199,7 +199,7 @@ public function getLocale($type = Locale::ACTUAL_LOCALE)
199199
*
200200
* @throws MethodNotImplementedException
201201
*/
202-
public function getSortKey($string)
202+
public function getSortKey(string $string)
203203
{
204204
throw new MethodNotImplementedException(__METHOD__);
205205
}
@@ -230,7 +230,7 @@ public function getStrength()
230230
*
231231
* @throws MethodNotImplementedException
232232
*/
233-
public function setAttribute($attr, $val)
233+
public function setAttribute(int $attr, int $val)
234234
{
235235
throw new MethodNotImplementedException(__METHOD__);
236236
}
@@ -252,7 +252,7 @@ public function setAttribute($attr, $val)
252252
*
253253
* @throws MethodNotImplementedException
254254
*/
255-
public function setStrength($strength)
255+
public function setStrength(int $strength)
256256
{
257257
throw new MethodNotImplementedException(__METHOD__);
258258
}
@@ -268,7 +268,7 @@ public function setStrength($strength)
268268
*
269269
* @throws MethodNotImplementedException
270270
*/
271-
public function sortWithSortKeys(&$arr)
271+
public function sortWithSortKeys(array &$arr)
272272
{
273273
throw new MethodNotImplementedException(__METHOD__);
274274
}
@@ -288,7 +288,7 @@ public function sortWithSortKeys(&$arr)
288288
*
289289
* @throws MethodNotImplementedException
290290
*/
291-
public function sort(&$arr, $sortFlag = self::SORT_REGULAR)
291+
public function sort(array &$arr, int $sortFlag = self::SORT_REGULAR)
292292
{
293293
throw new MethodNotImplementedException(__METHOD__);
294294
}

src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ interface BundleCompilerInterface
2323
/**
2424
* Compiles a resource bundle at the given source to the given target
2525
* directory.
26-
*
27-
* @param string $sourcePath
28-
* @param string $targetDir
2926
*/
30-
public function compile($sourcePath, $targetDir);
27+
public function compile(string $sourcePath, string $targetDir);
3128
}

src/Symfony/Component/Intl/Data/Bundle/Compiler/GenrbCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(string $genrb = 'genrb', string $envVars = '')
4646
/**
4747
* {@inheritdoc}
4848
*/
49-
public function compile($sourcePath, $targetDir)
49+
public function compile(string $sourcePath, string $targetDir)
5050
{
5151
if (is_dir($sourcePath)) {
5252
$sourcePath .= '/*.txt';

src/Symfony/Component/Intl/Data/Bundle/Reader/BufferedBundleReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(BundleReaderInterface $reader, int $bufferSize)
3737
/**
3838
* {@inheritdoc}
3939
*/
40-
public function read($path, $locale)
40+
public function read(string $path, string $locale)
4141
{
4242
$hash = $path.'//'.$locale;
4343

src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReader.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@ public function __construct(BundleReaderInterface $reader)
5353
*
5454
* @param array $localeAliases A mapping of locale aliases to locales
5555
*/
56-
public function setLocaleAliases($localeAliases)
56+
public function setLocaleAliases(array $localeAliases)
5757
{
5858
$this->localeAliases = $localeAliases;
5959
}
6060

6161
/**
6262
* {@inheritdoc}
6363
*/
64-
public function read($path, $locale)
64+
public function read(string $path, string $locale)
6565
{
6666
return $this->reader->read($path, $locale);
6767
}
6868

6969
/**
7070
* {@inheritdoc}
7171
*/
72-
public function readEntry($path, $locale, array $indices, $fallback = true)
72+
public function readEntry(string $path, string $locale, array $indices, bool $fallback = true)
7373
{
7474
$entry = null;
7575
$isMultiValued = false;

src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReaderInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ interface BundleEntryReaderInterface extends BundleReaderInterface
3838
* $reader->readEntry('...', 'en', ['TopLevel', 'NestedLevel', 'Entry']);
3939
*
4040
* @param string $path The path to the resource bundle
41-
* @param string $locale The locale to read
4241
* @param string[] $indices The indices to read from the bundle
4342
* @param bool $fallback Whether to merge the value with the value from
4443
* the fallback locale (e.g. "en" for "en_GB").
@@ -51,5 +50,5 @@ interface BundleEntryReaderInterface extends BundleReaderInterface
5150
*
5251
* @throws MissingResourceException If the indices cannot be accessed
5352
*/
54-
public function readEntry($path, $locale, array $indices, $fallback = true);
53+
public function readEntry(string $path, string $locale, array $indices, bool $fallback = true);
5554
}

src/Symfony/Component/Intl/Data/Bundle/Reader/BundleReaderInterface.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,8 @@
2121
interface BundleReaderInterface
2222
{
2323
/**
24-
* Reads a resource bundle.
25-
*
26-
* @param string $path The path to the resource bundle
27-
* @param string $locale The locale to read
28-
*
2924
* @return mixed returns an array or {@link \ArrayAccess} instance for
3025
* complex data, a scalar value otherwise
3126
*/
32-
public function read($path, $locale);
27+
public function read(string $path, string $locale);
3328
}

src/Symfony/Component/Intl/Data/Bundle/Reader/IntlBundleReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class IntlBundleReader implements BundleReaderInterface
2626
/**
2727
* {@inheritdoc}
2828
*/
29-
public function read($path, $locale)
29+
public function read(string $path, string $locale)
3030
{
3131
// Point for future extension: Modify this class so that it works also
3232
// if the \ResourceBundle class is not available.

src/Symfony/Component/Intl/Data/Bundle/Reader/JsonBundleReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class JsonBundleReader implements BundleReaderInterface
2626
/**
2727
* {@inheritdoc}
2828
*/
29-
public function read($path, $locale)
29+
public function read(string $path, string $locale)
3030
{
3131
$fileName = $path.'/'.$locale.'.json';
3232

src/Symfony/Component/Intl/Data/Bundle/Reader/PhpBundleReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PhpBundleReader implements BundleReaderInterface
2626
/**
2727
* {@inheritdoc}
2828
*/
29-
public function read($path, $locale)
29+
public function read(string $path, string $locale)
3030
{
3131
$fileName = $path.'/'.$locale.'.php';
3232

src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ interface BundleWriterInterface
2323
/**
2424
* Writes data to a resource bundle.
2525
*
26-
* @param string $path The path to the resource bundle
27-
* @param string $locale The locale to (over-)write
28-
* @param mixed $data The data to write
26+
* @param mixed $data The data to write
2927
*/
30-
public function write($path, $locale, $data);
28+
public function write(string $path, string $locale, $data);
3129
}

src/Symfony/Component/Intl/Data/Bundle/Writer/JsonBundleWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class JsonBundleWriter implements BundleWriterInterface
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function write($path, $locale, $data)
26+
public function write(string $path, string $locale, $data)
2727
{
2828
if ($data instanceof \Traversable) {
2929
$data = iterator_to_array($data);

src/Symfony/Component/Intl/Data/Bundle/Writer/PhpBundleWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PhpBundleWriter implements BundleWriterInterface
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function write($path, $locale, $data)
26+
public function write(string $path, string $locale, $data)
2727
{
2828
$template = <<<'TEMPLATE'
2929
<?php

src/Symfony/Component/Intl/Data/Bundle/Writer/TextBundleWriter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TextBundleWriter implements BundleWriterInterface
2929
/**
3030
* {@inheritdoc}
3131
*/
32-
public function write($path, $locale, $data, $fallback = true)
32+
public function write(string $path, string $locale, $data, bool $fallback = true)
3333
{
3434
$file = fopen($path.'/'.$locale.'.txt', 'w');
3535

src/Symfony/Component/Intl/Data/Generator/AbstractDataGenerator.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,26 @@ public function generateData(GeneratorConfig $config)
9191
}
9292

9393
/**
94-
* @param string $sourceDir
95-
*
9694
* @return string[]
9795
*/
98-
abstract protected function scanLocales(LocaleScanner $scanner, $sourceDir);
96+
abstract protected function scanLocales(LocaleScanner $scanner, string $sourceDir);
9997

100-
/**
101-
* @param string $sourceDir
102-
* @param string $tempDir
103-
*/
104-
abstract protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir);
98+
abstract protected function compileTemporaryBundles(BundleCompilerInterface $compiler, string $sourceDir, string $tempDir);
10599

106100
abstract protected function preGenerate();
107101

108102
/**
109-
* @param string $tempDir
110-
* @param string $displayLocale
111-
*
112103
* @return array|null
113104
*/
114-
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale);
105+
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale);
115106

116107
/**
117-
* @param string $tempDir
118-
*
119108
* @return array|null
120109
*/
121-
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir);
110+
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, string $tempDir);
122111

123112
/**
124-
* @param string $tempDir
125-
*
126113
* @return array|null
127114
*/
128-
abstract protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir);
115+
abstract protected function generateDataForMeta(BundleEntryReaderInterface $reader, string $tempDir);
129116
}

src/Symfony/Component/Intl/Data/Generator/CurrencyDataGenerator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class CurrencyDataGenerator extends AbstractDataGenerator
5151
/**
5252
* {@inheritdoc}
5353
*/
54-
protected function scanLocales(LocaleScanner $scanner, $sourceDir)
54+
protected function scanLocales(LocaleScanner $scanner, string $sourceDir)
5555
{
5656
return $scanner->scanLocales($sourceDir.'/curr');
5757
}
5858

5959
/**
6060
* {@inheritdoc}
6161
*/
62-
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, $sourceDir, $tempDir)
62+
protected function compileTemporaryBundles(BundleCompilerInterface $compiler, string $sourceDir, string $tempDir)
6363
{
6464
$compiler->compile($sourceDir.'/curr', $tempDir);
6565
$compiler->compile($sourceDir.'/misc/currencyNumericCodes.txt', $tempDir);
@@ -76,7 +76,7 @@ protected function preGenerate()
7676
/**
7777
* {@inheritdoc}
7878
*/
79-
protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale)
79+
protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale)
8080
{
8181
$localeBundle = $reader->read($tempDir, $displayLocale);
8282

@@ -95,7 +95,7 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, $te
9595
/**
9696
* {@inheritdoc}
9797
*/
98-
protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir)
98+
protected function generateDataForRoot(BundleEntryReaderInterface $reader, string $tempDir)
9999
{
100100
$rootBundle = $reader->read($tempDir, 'root');
101101

@@ -108,7 +108,7 @@ protected function generateDataForRoot(BundleEntryReaderInterface $reader, $temp
108108
/**
109109
* {@inheritdoc}
110110
*/
111-
protected function generateDataForMeta(BundleEntryReaderInterface $reader, $tempDir)
111+
protected function generateDataForMeta(BundleEntryReaderInterface $reader, string $tempDir)
112112
{
113113
$rootBundle = $reader->read($tempDir, 'root');
114114
$supplementalDataBundle = $reader->read($tempDir, 'supplementalData');

src/Symfony/Component/Intl/Data/Generator/FallbackTrait.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,18 @@ trait FallbackTrait
2525
private $generatingFallback = false;
2626

2727
/**
28-
* @param string $tempDir
29-
* @param string $displayLocale
30-
*
3128
* @return array|null
3229
*
3330
* @see AbstractDataGenerator::generateDataForLocale()
3431
*/
35-
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, $tempDir, $displayLocale);
32+
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale);
3633

3734
/**
38-
* @param string $tempDir
39-
*
4035
* @return array|null
4136
*
4237
* @see AbstractDataGenerator::generateDataForRoot()
4338
*/
44-
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, $tempDir);
39+
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, string $tempDir);
4540

4641
private function generateFallbackData(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale): array
4742
{

src/Symfony/Component/Intl/Data/Generator/GeneratorConfig.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ public function __construct(string $sourceDir, string $icuVersion)
3838

3939
/**
4040
* Adds a writer to be used during the data conversion.
41-
*
42-
* @param string $targetDir The output directory
4341
*/
44-
public function addBundleWriter($targetDir, BundleWriterInterface $writer)
42+
public function addBundleWriter(string $targetDir, BundleWriterInterface $writer)
4543
{
4644
$this->bundleWriters[$targetDir] = $writer;
4745
}

0 commit comments

Comments
 (0)
0