Skip to content

Commit 8e9e087

Browse files
ValentineBoineaunicolas-grekas
authored andcommitted
[Intl] Add Union Types
1 parent 7c59e35 commit 8e9e087

14 files changed

+33
-47
lines changed

Countries.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static function getAlpha3Name(string $alpha3Code, string $displayLocale =
109109
*
110110
* @return string[]
111111
*/
112-
public static function getNames($displayLocale = null): array
112+
public static function getNames(?string $displayLocale = null): array
113113
{
114114
return self::asort(self::readEntry(['Names'], $displayLocale), $displayLocale);
115115
}
@@ -121,7 +121,7 @@ public static function getNames($displayLocale = null): array
121121
*
122122
* @return string[]
123123
*/
124-
public static function getAlpha3Names($displayLocale = null): array
124+
public static function getAlpha3Names(?string $displayLocale = null): array
125125
{
126126
$alpha2Names = self::getNames($displayLocale);
127127
$alpha3Names = [];

Data/Bundle/Writer/BundleWriterInterface.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,5 @@
2020
*/
2121
interface BundleWriterInterface
2222
{
23-
/**
24-
* Writes data to a resource bundle.
25-
*
26-
* @param mixed $data The data to write
27-
*/
28-
public function write(string $path, string $locale, $data);
23+
public function write(string $path, string $locale, mixed $data);
2924
}

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(string $path, string $locale, $data)
26+
public function write(string $path, string $locale, mixed $data)
2727
{
2828
if ($data instanceof \Traversable) {
2929
$data = iterator_to_array($data);

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(string $path, string $locale, $data)
26+
public function write(string $path, string $locale, mixed $data)
2727
{
2828
$template = <<<'TEMPLATE'
2929
<?php

Data/Bundle/Writer/TextBundleWriter.php

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

@@ -46,7 +46,7 @@ public function write(string $path, string $locale, $data, bool $fallback = true
4646
*
4747
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
4848
*/
49-
private function writeResourceBundle($file, string $bundleName, $value, bool $fallback)
49+
private function writeResourceBundle($file, string $bundleName, mixed $value, bool $fallback)
5050
{
5151
fwrite($file, $bundleName);
5252

@@ -63,7 +63,7 @@ private function writeResourceBundle($file, string $bundleName, $value, bool $fa
6363
*
6464
* @see http://source.icu-project.org/repos/icu/icuhtml/trunk/design/bnf_rb.txt
6565
*/
66-
private function writeResource($file, $value, int $indentation, bool $requireBraces = true)
66+
private function writeResource($file, mixed $value, int $indentation, bool $requireBraces = true)
6767
{
6868
if (\is_int($value)) {
6969
$this->writeInteger($file, $value);

Data/Generator/RegionDataGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class RegionDataGenerator extends AbstractDataGenerator
6767
*/
6868
private $regionCodes = [];
6969

70-
public static function isValidCountryCode($region)
70+
public static function isValidCountryCode(int|string|null $region)
7171
{
7272
if (isset(self::DENYLIST[$region])) {
7373
return false;

Data/Util/ArrayAccessibleResourceBundle.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,29 @@ public function __construct(\ResourceBundle $bundleImpl)
3232
$this->bundleImpl = $bundleImpl;
3333
}
3434

35-
public function get($offset)
35+
public function get(int|string $offset)
3636
{
3737
$value = $this->bundleImpl->get($offset);
3838

3939
return $value instanceof \ResourceBundle ? new static($value) : $value;
4040
}
4141

42-
public function offsetExists($offset): bool
42+
public function offsetExists(mixed $offset): bool
4343
{
4444
return null !== $this->bundleImpl->get($offset);
4545
}
4646

47-
public function offsetGet($offset)
47+
public function offsetGet(mixed $offset)
4848
{
4949
return $this->get($offset);
5050
}
5151

52-
public function offsetSet($offset, $value)
52+
public function offsetSet(mixed $offset, mixed $value)
5353
{
5454
throw new BadMethodCallException('Resource bundles cannot be modified.');
5555
}
5656

57-
public function offsetUnset($offset)
57+
public function offsetUnset(mixed $offset)
5858
{
5959
throw new BadMethodCallException('Resource bundles cannot be modified.');
6060
}

Data/Util/RecursiveArrayAccess.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,14 @@
2020
*/
2121
class RecursiveArrayAccess
2222
{
23-
public static function get($array, array $indices)
23+
public static function get(array|\ArrayAccess $array, array $indices)
2424
{
2525
foreach ($indices as $index) {
26-
// Use array_key_exists() for arrays, isset() otherwise
27-
if (\is_array($array)) {
28-
if (\array_key_exists($index, $array)) {
29-
$array = $array[$index];
30-
continue;
31-
}
32-
} elseif ($array instanceof \ArrayAccess) {
33-
if (isset($array[$index])) {
34-
$array = $array[$index];
35-
continue;
36-
}
26+
if (\is_array($array) ? !\array_key_exists($index, $array) : !isset($array[$index])) {
27+
throw new OutOfBoundsException(sprintf('The index "%s" does not exist.', $index));
3728
}
3829

39-
throw new OutOfBoundsException(sprintf('The index "%s" does not exist.', $index));
30+
$array = $array[$index];
4031
}
4132

4233
return $array;

Data/Util/RingBuffer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ public function __construct(int $size)
4242
/**
4343
* {@inheritdoc}
4444
*/
45-
public function offsetExists($key): bool
45+
public function offsetExists(mixed $key): bool
4646
{
4747
return isset($this->indices[$key]);
4848
}
4949

5050
/**
5151
* {@inheritdoc}
5252
*/
53-
public function offsetGet($key)
53+
public function offsetGet(mixed $key)
5454
{
5555
if (!isset($this->indices[$key])) {
5656
throw new OutOfBoundsException(sprintf('The index "%s" does not exist.', $key));
@@ -62,7 +62,7 @@ public function offsetGet($key)
6262
/**
6363
* {@inheritdoc}
6464
*/
65-
public function offsetSet($key, $value)
65+
public function offsetSet(mixed $key, mixed $value)
6666
{
6767
if (false !== ($keyToRemove = array_search($this->cursor, $this->indices))) {
6868
unset($this->indices[$keyToRemove]);
@@ -77,7 +77,7 @@ public function offsetSet($key, $value)
7777
/**
7878
* {@inheritdoc}
7979
*/
80-
public function offsetUnset($key)
80+
public function offsetUnset(mixed $key)
8181
{
8282
if (isset($this->indices[$key])) {
8383
$this->values[$this->indices[$key]] = null;

Exception/UnexpectedTypeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class UnexpectedTypeException extends InvalidArgumentException
2020
{
21-
public function __construct($value, string $expectedType)
21+
public function __construct(mixed $value, string $expectedType)
2222
{
2323
parent::__construct(sprintf('Expected argument of type "%s", "%s" given', $expectedType, get_debug_type($value)));
2424
}

0 commit comments

Comments
 (0)