8000 [Intl][5.0] add type-hints even for params that are not supported anyway · symfony/symfony@9857e4d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9857e4d

Browse files
author
Philippe Segatori
committed
[Intl][5.0] add type-hints even for params that are not supported anyway
1 parent a55cba4 commit 9857e4d

File tree

8 files changed

+36
-55
lines changed

8 files changed

+36
-55
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Collator
7070
const SORT_STRING = 1;
7171

7272
/**
73-
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
73+
* @param string|null $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
7474
*
7575
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
7676
*/
@@ -84,13 +84,13 @@ public function __construct(?string $locale)
8484
/**
8585
* Static constructor.
8686
*
87-
* @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
87+
* @param string|null $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en")
8888
*
8989
* @return self
9090
*
9191
* @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed
9292
*/
93-
public static function create(string $locale)
93+
public static function create(?string $locale)
9494
{
9595
return new self($locale);
9696
}
@@ -106,7 +106,7 @@ public static function create(string $locale)
106106
*
107107
* @return bool True on success or false on failure
108108
*/
109-
public function asort(&$array, int $sortFlag = self::SORT_REGULAR)
109+
public function asort(array &$array, int $sortFlag = self::SORT_REGULAR)
110110
{
111111
$intlToPlainFlagMap = [
112112
self::SORT_REGULAR => \SORT_REGULAR,
@@ -268,7 +268,7 @@ public function setStrength(int $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, int $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/Writer/TextBundleWriter.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TextBundleWriter implements BundleWriterInterface
3131
/**
3232
* {@inheritdoc}
3333
*/
34-
public function write(string $path, string $locale, $data, $fallback = true)
34+
public function write(string $path, string $locale, $data, bool $fallback = true)
3535
{
3636
$file = fopen($path.'/'.$locale.'.txt', 'w');
3737

@@ -189,10 +189,6 @@ private function writeArray($file, array $value, int $indentation)
189189
*/
190190
private function writeTable($file, iterable $value, int $indentation, bool $fallback = true)
191191
{
192-
if (!\is_array($value) && !$value instanceof \Traversable) {
193-
throw new UnexpectedTypeException($value, 'array or \Traversable');
194-
}
195-
196192
if (!$fallback) {
197193
fwrite($file, ':table(nofallback)');
198194
}

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,21 @@ public function generateData(GeneratorConfig $config)
9595
*/
9696
abstract protected function scanLocales(LocaleScanner $scanner, string $sourceDir);
9797

98-
/**
99-
* @param string $sourceDir
100-
* @param string $tempDir
101-
*/
10298
abstract protected function compileTemporaryBundles(BundleCompilerInterface $compiler, string $sourceDir, string $tempDir);
10399

104100
abstract protected function preGenerate();
105101

106102
/**
107-
* @param string $tempDir
108-
* @param string $displayLocale
109-
*
110103
* @return array|null
111104
*/
112105
abstract protected function generateDataForLocale(BundleEntryReaderInterface $reader, string $tempDir, string $displayLocale);
113106

114107
/**
115-
* @param string $tempDir
116-
*
117108
* @return array|null
118109
*/
119110
abstract protected function generateDataForRoot(BundleEntryReaderInterface $reader, string $tempDir);
120111

121112
/**
122-
* @param string $tempDir
123-
*
124113
* @return array|null
125114
*/
126115
abstract protected function generateDataForMeta(BundleEntryReaderInterface $reader, string $tempDir);

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,13 @@ 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
*/
3532
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()

src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function format($timestamp)
235235
*
236236
* @throws MethodNotImplementedException
237237
*/
238-
public function formatObject($object, $format = null, $locale = null)
238+
public function formatObject(object $object, $format = null, string $locale = null)
239239
{
240240
throw new MethodNotImplementedException(__METHOD__);
241241
}
@@ -313,7 +313,7 @@ public function getErrorMessage()
313313
*
314314
* @see http://www.php.net/manual/en/intldateformatter.getlocale.php
315315
*/
316-
public function getLocale($type = Locale::ACTUAL_LOCALE)
316+
public function getLocale(int $type = Locale::ACTUAL_LOCALE)
317317
{
318318
return 'en';
319319
}
@@ -401,7 +401,7 @@ public function isLenient()
401401
*
402402
* @throws MethodNotImplementedException
403403
*/
404-
public function localtime($value, &$position = 0)
404+
public function localtime(string $value, int &$position = 0)
405405
{
406406
throw new MethodNotImplementedException(__METHOD__);
407407
}
@@ -451,7 +451,7 @@ public function parse(string $value, int &$position = null)
451451
*
452452
* @throws MethodNotImplementedException
453453
*/
454-
public function setCalendar($calendar)
454+
public function setCalendar(string $calendar)
455455
{
456456
throw new MethodNotImplementedException(__METHOD__);
457457
}
@@ -473,7 +473,7 @@ public function setCalendar($calendar)
473473
*
474474
* @throws MethodArgumentValueNotImplementedException When $lenient is true
475475
*/
476-
public function setLenient($lenient)
476+
public function setLenient(bool $lenient)
477477
{
478478
if ($lenient) {
479479
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'lenient', $lenient, 'Only the strict parser is supported');

src/Symfony/Component/Intl/Locale/Locale.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public static function composeLocale(array $subtags)
115115
*
116116
* @throws MethodNotImplementedException
117117
*/
118-
public static function filterMatches($langtag, $locale, $canonicalize = false)
118+
public static function filterMatches(string $langtag, string $locale, bool $canonicalize = false)
119119
{
120120
throw new MethodNotImplementedException(__METHOD__);
121121
}
@@ -131,7 +131,7 @@ public static function filterMatches($langtag, $locale, $canonicalize = false)
131131
*
132132
* @throws MethodNotImplementedException
133133
*/
134-
public static function getAllVariants($locale)
134+
public static function getAllVariants(string $locale)
135135
{
136136
throw new MethodNotImplementedException(__METHOD__);
137137
}
@@ -160,7 +160,7 @@ public static function getDefault()
160160
*
161161
* @throws MethodNotImplementedException
162162
*/
163-
public static function getDisplayLanguage($locale, $inLocale = null)
163+
public static function getDisplayLanguage(string $locale, string $inLocale = null)
164164
{
165165
throw new MethodNotImplementedException(__METHOD__);
166166
}
@@ -177,7 +177,7 @@ public static function getDisplayLanguage($locale, $inLocale = null)
177177
*
178178
* @throws MethodNotImplementedException
179179
*/
180-
public static function getDisplayName($locale, $inLocale = null)
180+
public static function getDisplayName(string $locale, string $inLocale = null)
181181
{
182182
throw new MethodNotImplementedException(__METHOD__);
183183
}
@@ -194,7 +194,7 @@ public static function getDisplayName($locale, $inLocale = null)
194194
*
195195
* @throws MethodNotImplementedException
196196
*/
197-
public static function getDisplayRegion($locale, $inLocale = null)
197+
public static function getDisplayRegion(string $locale, string $inLocale = null)
198198
{
199199
throw new MethodNotImplementedException(__METHOD__);
200200
}
@@ -211,7 +211,7 @@ public static function getDisplayRegion($locale, $inLocale = null)
211211
*
212212
* @throws MethodNotImplementedException
213213
*/
214-
public static function getDisplayScript($locale, $inLocale = null)
214+
public static function getDisplayScript(string $locale, string $inLocale = null)
215215
{
216216
throw new MethodNotImplementedException(__METHOD__);
217217
}
@@ -228,7 +228,7 @@ public static function getDisplayScript($locale, $inLocale = null)
228228
*
229229
* @throws MethodNotImplementedException
230230
*/
231-
public static function getDisplayVariant($locale, $inLocale = null)
231+
public static function getDisplayVariant(string $locale, string $inLocale = null)
232232
{
233233
throw new MethodNotImplementedException(__METHOD__);
234234
}
@@ -244,7 +244,7 @@ public static function getDisplayVariant($locale, $inLocale = null)
244244
*
245245
* @throws MethodNotImplementedException
246246
*/
247-
public static function getKeywords($locale)
247+
public static function getKeywords(string $ 10000 locale)
248248
{
249249
throw new MethodNotImplementedException(__METHOD__);
250250
}
@@ -260,7 +260,7 @@ public static function getKeywords($locale)
260260
*
261261
* @throws MethodNotImplementedException
262262
*/
263-
public static function getPrimaryLanguage($locale)
263+
public static function getPrimaryLanguage(string $locale)
264264
{
265265
throw new MethodNotImplementedException(__METHOD__);
266266
}
@@ -276,7 +276,7 @@ public static function getPrimaryLanguage($locale)
276276
*
277277
* @throws MethodNotImplementedException
278278
*/
279-
public static function getRegion($locale)
279+
public static function getRegion(string $locale)
280280
{
281281
throw new MethodNotImplementedException(__METHOD__);
282282
}
@@ -292,7 +292,7 @@ public static function getRegion($locale)
292292
*
293293
* @throws MethodNotImplementedException
294294
*/
295-
public static function getScript($locale)
295+
public static function getScript(string $locale)
296296
{
297297
throw new MethodNotImplementedException(__METHOD__);
298298
}
@@ -309,7 +309,7 @@ public static function getScript($locale)
309309
*
310310
* @throws MethodNotImplementedException
311311
*/
312-
public static function lookup(array $langtag, $locale, $canonicalize = false, $default = null)
312+
public static function lookup(array $langtag, string $locale, bool $canonicalize = false, string $default = null)
313313
{
314314
throw new MethodNotImplementedException(__METHOD__);
315315
}
@@ -325,7 +325,7 @@ public static function lookup(array $langtag, $locale, $canonicalize = false, $d
325325
*
326326
* @throws MethodNotImplementedException
327327
*/
328-
public static function parseLocale($locale)
328+
public static function parseLocale(string $locale)
329329
{
330330
throw new MethodNotImplementedException(__METHOD__);
331331
}

src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ class NumberFormatter
257257
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
258258
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
259259
*/
260-
public function __construct(?string $locale = 'en', int $style = null, $pattern = null)
260+
public function __construct(?string $locale = 'en', int $style = null, string $pattern = null)
261261
{
262262
if ('en' !== $locale && null !== $locale) {
263263
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
@@ -296,7 +296,7 @@ public function __construct(?string $locale = 'en', int $style = null, $pattern
296296
* @throws MethodArgumentValueNotImplementedException When the $style is not supported
297297
* @throws MethodArgumentNotImplementedException When the pattern value is different than null
298298
*/
299-
public static function create(?string $locale = 'en', int $style = null, $pattern = null)
299+
public static function create(?string $locale = 'en', int $style = null, string $pattern = null)
300300
{
301301
return new self($locale, $style, $pattern);
302302
}
@@ -489,7 +489,7 @@ public function getTextAttribute(int $attr)
489489
*
490490
* @throws MethodNotImplementedException
491491
*/
492-
public function parseCurrency($value, &$currency, &$position = null)
492+
public function parseCurrency(string $value, string &$currency, int &$position = null)
493493
{
494494
throw new MethodNotImplementedException(__METHOD__);
495495
}
@@ -611,7 +611,7 @@ public function setAttribute(int $attr, int $value)
611611
*
612612
* @throws MethodNotImplementedException
613613
*/
614-
public function setPattern($pattern)
614+
public function setPattern(string $pattern)
615615
{
616616
throw new MethodNotImplementedException(__METHOD__);
617617
}
@@ -628,7 +628,7 @@ public function setPattern($pattern)
628628
*
629629
* @throws MethodNotImplementedException
630630
*/
631-
public function setSymbol($attr, $value)
631+
public function setSymbol(int $attr, string $value)
632632
{
633633
throw new MethodNotImplementedException(__METHOD__);
634634
}
@@ -645,7 +645,7 @@ public function setSymbol($attr, $value)
645645
*
646646
* @throws MethodNotImplementedException
647647
*/
648-
public function setTextAttribute($attr, $value)
648+
public function setTextAttribute(int $attr, string $value)
649649
{
650650
throw new MethodNotImplementedException(__METHOD__);
651651
}

src/Symfony/Component/Intl/Tests/NumberFormatter/NumberFormatterTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,29 @@ public function testParseCurrency()
148148
{
149149
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
150150
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
151-
$formatter->parseCurrency(null, $currency);
151+
$currency = 'USD';
152+
$formatter->parseCurrency(3, $currency);
152153
}
153154

154155
public function testSetPattern()
155156
{
156157
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
157158
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
158-
$formatter->setPattern(null);
159+
$formatter->setPattern('#0');
159160
}
160161

161162
public function testSetSymbol()
162163
{
163164
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
164165
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
165-
$formatter->setSymbol(null, null);
166+
$formatter->setSymbol(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '*');
166167
}
167168

168169
public function testSetTextAttribute()
169170
{
170171
$this->expectException('Symfony\Component\Intl\Exception\MethodNotImplementedException');
171172
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
172-
$formatter->setTextAttribute(null, null);
173+
$formatter->setTextAttribute(NumberFormatter::NEGATIVE_PREFIX, '-');
173174
}
174175

175176
protected function getNumberFormatter($locale = 'en', $style = null, $pattern = null)

0 commit comments

Comments
 (0)
0