Skip to content

Commit 77e720d

Browse files
Merge branch '4.4' into 5.1
* 4.4: Changed private static array-properties to const
2 parents 057d034 + 70ec8ba commit 77e720d

13 files changed

+106
-108
lines changed

Data/Generator/CurrencyDataGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class CurrencyDataGenerator extends AbstractDataGenerator
2727
{
28-
private static $denylist = [
28+
private const DENYLIST = [
2929
'XBA' => true, // European Composite Unit
3030
'XBB' => true, // European Monetary Unit
3131
'XBC' => true, // European Unit of Account (XBC)
@@ -133,7 +133,7 @@ private function generateSymbolNamePairs(ArrayAccessibleResourceBundle $rootBund
133133
$symbolNamePairs = iterator_to_array($rootBundle['Currencies']);
134134

135135
// Remove unwanted currencies
136-
$symbolNamePairs = array_diff_key($symbolNamePairs, self::$denylist);
136+
$symbolNamePairs = array_diff_key($symbolNamePairs, self::DENYLIST);
137137

138138
return $symbolNamePairs;
139139
}

Data/Generator/LanguageDataGenerator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class LanguageDataGenerator extends AbstractDataGenerator
2929
/**
3030
* Source: https://iso639-3.sil.org/code_tables/639/data.
3131
*/
32-
private static $preferredAlpha2ToAlpha3Mapping = [
32+
private const PREFERRED_ALPHA2_TO_ALPHA3_MAPPING = [
3333
'ak' => 'aka',
3434
'ar' => 'ara',
3535
'ay' => 'aym',
@@ -83,7 +83,7 @@ class LanguageDataGenerator extends AbstractDataGenerator
8383
'za' => 'zha',
8484
'zh' => 'zho',
8585
];
86-
private static $denylist = [
86+
private const DENYLIST = [
8787
'root' => true, // Absolute root language
8888
'mul' => true, // Multiple languages
8989
'mis' => true, // Uncoded language
@@ -182,7 +182,7 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
182182

183183
private static function generateLanguageNames(ArrayAccessibleResourceBundle $localeBundle): array
184184
{
185-
return array_diff_key(iterator_to_array($localeBundle['Languages']), self::$denylist);
185+
return array_diff_key(iterator_to_array($localeBundle['Languages']), self::DENYLIST);
186186
}
187187

188188
private function generateAlpha3Codes(array $languageCodes, ArrayAccessibleResourceBundle $metadataBundle): array
@@ -210,13 +210,13 @@ private function generateAlpha2ToAlpha3Mapping(ArrayAccessibleResourceBundle $me
210210
foreach ($aliases as $alias => $data) {
211211
$language = $data['replacement'];
212212
if (2 === \strlen($language) && 3 === \strlen($alias) && 'overlong' === $data['reason']) {
213-
if (isset(self::$preferredAlpha2ToAlpha3Mapping[$language])) {
213+
if (isset(self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$language])) {
214214
// Validate to prevent typos
215-
if (!isset($aliases[self::$preferredAlpha2ToAlpha3Mapping[$language]])) {
216-
throw new RuntimeException('The statically set three-letter mapping '.self::$preferredAlpha2ToAlpha3Mapping[$language].' for the language code '.$language.' seems to be invalid. Typo?');
215+
if (!isset($aliases[self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$language]])) {
216+
throw new RuntimeException('The statically set three-letter mapping '.self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$language].' for the language code '.$language.' seems to be invalid. Typo?');
217217
}
218218

219-
$alpha3 = self::$preferredAlpha2ToAlpha3Mapping[$language];
219+
$alpha3 = self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$language];
220220
$alpha2 = $aliases[$alpha3]['replacement'];
221221

222222
if ($language !== $alpha2) {
@@ -225,7 +225,7 @@ private function generateAlpha2ToAlpha3Mapping(ArrayAccessibleResourceBundle $me
225225

226226
$alpha2ToAlpha3[$language] = $alpha3;
227227
} elseif (isset($alpha2ToAlpha3[$language])) {
228-
throw new RuntimeException('Multiple three-letter mappings exist for the language code '.$language.'. Please add one of them to the property $preferredAlpha2ToAlpha3Mapping.');
228+
throw new RuntimeException('Multiple three-letter mappings exist for the language code '.$language.'. Please add one of them to the const PREFERRED_ALPHA2_TO_ALPHA3_MAPPING.');
229229
} else {
230230
$alpha2ToAlpha3[$language] = $alias;
231231
}

Data/Generator/RegionDataGenerator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RegionDataGenerator extends AbstractDataGenerator
3131
/**
3232
* Source: https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes.
3333
*/
34-
private static $preferredAlpha2ToAlpha3Mapping = [
34+
private const PREFERRED_ALPHA2_TO_ALPHA3_MAPPING = [
3535
'CD' => 'COD',
3636
'DE' => 'DEU',
3737
'FR' => 'FRA',
@@ -40,7 +40,7 @@ class RegionDataGenerator extends AbstractDataGenerator
4040
'YE' => 'YEM',
4141
];
4242

43-
private static $denylist = [
43+
private const DENYLIST = [
4444
// Exceptional reservations
4545
'AC' => true, // Ascension Island
4646
'CP' => true, // Clipperton Island
@@ -69,7 +69,7 @@ class RegionDataGenerator extends AbstractDataGenerator
6969

7070
public static function isValidCountryCode($region)
7171
{
72-
if (isset(self::$denylist[$region])) {
72+
if (isset(self::DENYLIST[$region])) {
7373
return false;
7474
}
7575

@@ -181,13 +181,13 @@ private function generateAlpha2ToAlpha3Mapping(array $countries, ArrayAccessible
181181
foreach ($aliases as $alias => $data) {
182182
$country = $data['replacement'];
183183
if (2 === \strlen($country) && 3 === \strlen($alias) && 'overlong' === $data['reason']) {
184-
if (isset(self::$preferredAlpha2ToAlpha3Mapping[$country])) {
184+
if (isset(self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country])) {
185185
// Validate to prevent typos
186-
if (!isset($aliases[self::$preferredAlpha2ToAlpha3Mapping[$country]])) {
187-
throw new RuntimeException('The statically set three-letter mapping '.self::$preferredAlpha2ToAlpha3Mapping[$country].' for the country code '.$country.' seems to be invalid. Typo?');
186+
if (!isset($aliases[self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country]])) {
187+
throw new RuntimeException('The statically set three-letter mapping '.self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country].' for the country code '.$country.' seems to be invalid. Typo?');
188188
}
189189

190-
$alpha3 = self::$preferredAlpha2ToAlpha3Mapping[$country];
190+
$alpha3 = self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country];
191191
$alpha2 = $aliases[$alpha3]['replacement'];
192192

193193
if ($country !== $alpha2) {
@@ -196,7 +196,7 @@ private function generateAlpha2ToAlpha3Mapping(array $countries, ArrayAccessible
196196

197197
$alpha2ToAlpha3[$country] = $alpha3;
198198
} elseif (isset($alpha2ToAlpha3[$country])) {
199-
throw new RuntimeException('Multiple three-letter mappings exist for the country code '.$country.'. Please add one of them to the property $preferredAlpha2ToAlpha3Mapping.');
199+
throw new RuntimeException('Multiple three-letter mappings exist for the country code '.$country.'. Please add one of them to the const PREFERRED_ALPHA2_TO_ALPHA3_MAPPING.');
200200
} elseif (isset($countries[$country]) && self::isValidCountryCode($alias)) {
201201
$alpha2ToAlpha3[$country] = $alias;
202202
}

Data/Generator/ScriptDataGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
class ScriptDataGenerator extends AbstractDataGenerator
2626
{
27-
private static $denylist = [
27+
private const DENYLIST = [
2828
'Zzzz' => true, // Unknown Script
2929
];
3030

@@ -69,7 +69,7 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, str
6969
// isset() on \ResourceBundle returns true even if the value is null
7070
if (isset($localeBundle['Scripts']) && null !== $localeBundle['Scripts']) {
7171
$data = [
72-
'Names' => array_diff_key(iterator_to_array($localeBundle['Scripts']), self::$denylist),
72+
'Names' => array_diff_key(iterator_to_array($localeBundle['Scripts']), self::DENYLIST),
7373
];
7474

7575
$this->scriptCodes = array_merge($this->scriptCodes, array_keys($data['Names']));

Globals/IntlGlobals.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract class IntlGlobals
3838
/**
3939
* All known error codes.
4040
*/
41-
private static $errorCodes = [
41+
private const ERROR_CODES = [
4242
self::U_ZERO_ERROR => 'U_ZERO_ERROR',
4343
self::U_ILLEGAL_ARGUMENT_ERROR => 'U_ILLEGAL_ARGUMENT_ERROR',
4444
self::U_PARSE_ERROR => 'U_PARSE_ERROR',
@@ -61,7 +61,7 @@ abstract class IntlGlobals
6161
*/
6262
public static function isFailure(int $errorCode): bool
6363
{
64-
return isset(self::$errorCodes[$errorCode])
64+
return isset(self::ERROR_CODES[$errorCode])
6565
&& $errorCode > self::U_ZERO_ERROR;
6666
}
6767

@@ -94,7 +94,7 @@ public static function getErrorMessage(): string
9494
*/
9595
public static function getErrorName(int $code): string
9696
{
97-
return self::$errorCodes[$code] ?? '[BOGUS UErrorCode]';
97+
return self::ERROR_CODES[$code] ?? '[BOGUS UErrorCode]';
9898
}
9999

100100
/**
@@ -107,11 +107,11 @@ public static function getErrorName(int $code): string
107107
*/
108108
public static function setError(int $code, string $message = '')
109109
{
110-
if (!isset(self::$errorCodes[$code])) {
110+
if (!isset(self::ERROR_CODES[$code])) {
111111
throw new \InvalidArgumentException(sprintf('No such error code: "%s".', $code));
112112
}
113113

114-
self::$errorMessage = $message ? sprintf('%s: %s', $message, self::$errorCodes[$code]) : self::$errorCodes[$code];
114+
self::$errorMessage = $message ? sprintf('%s: %s', $message, self::ERROR_CODES[$code]) : self::ERROR_CODES[$code];
115115
self::$errorCode = $code;
116116
}
117117
}

NumberFormatter/NumberFormatter.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,15 @@ abstract class NumberFormatter
165165
/**
166166
* The supported styles to the constructor $styles argument.
167167
*/
168-
private static $supportedStyles = [
168+
private const SUPPORTED_STYLES = [
169169
'CURRENCY' => self::CURRENCY,
170170
'DECIMAL' => self::DECIMAL,
171171
];
172172

173173
/**
174174
* Supported attributes to the setAttribute() $attr argument.
175175
*/
176-
private static $supportedAttributes = [
176+
private const SUPPORTED_ATTRIBUTES = [
177177
'FRACTION_DIGITS' => self::FRACTION_DIGITS,
178178
'GROUPING_USED' => self::GROUPING_USED,
179179
'ROUNDING_MODE' => self::ROUNDING_MODE,
@@ -184,7 +184,7 @@ abstract class NumberFormatter
184184
* NumberFormatter::ROUNDING_MODE. NumberFormatter::ROUND_DOWN
185185
* and NumberFormatter::ROUND_UP does not have a PHP only equivalent.
186186
*/
187-
private static $roundingModes = [
187+
private const ROUNDING_MODES = [
188188
'ROUND_HALFEVEN' => self::ROUND_HALFEVEN,
189189
'ROUND_HALFDOWN' => self::ROUND_HALFDOWN,
190190
'ROUND_HALFUP' => self::ROUND_HALFUP,
@@ -200,7 +200,7 @@ abstract class NumberFormatter
200200
*
201201
* @see https://php.net/round
202202
*/
203-
private static $phpRoundingMap = [
203+
private const PHP_ROUNDING_MAP = [
204204
self::ROUND_HALFDOWN => \PHP_ROUND_HALF_DOWN,
205205
self::ROUND_HALFEVEN => \PHP_ROUND_HALF_EVEN,
206206
self::ROUND_HALFUP => \PHP_ROUND_HALF_UP,
@@ -211,7 +211,7 @@ abstract class NumberFormatter
211211
* PHP's round() function, but there's an equivalent. Keys are rounding
212212
* modes, values does not matter.
213213
*/
214-
private static $customRoundingList = [
214+
private const CUSTOM_ROUNDING_LIST = [
215215
self::ROUND_CEILING => true,
216216
self::ROUND_FLOOR => true,
217217
self::ROUND_DOWN => true,
@@ -230,12 +230,12 @@ abstract class NumberFormatter
230230
*/
231231
private static $int64Max = 9223372036854775807;
232232

233-
private static $enSymbols = [
233+
private const EN_SYMBOLS = [
234234
self::DECIMAL => ['.', ',', ';', '%', '0', '#', '-', '+', '¤', '¤¤', '.', 'E', '', '*', '', 'NaN', '@', ','],
235235
self::CURRENCY => ['.', ',', ';', '%', '0', '#', '-', '+', '¤', '¤¤', '.', 'E', '', '*', '', 'NaN', '@', ','],
236236
];
237237

238-
private static $enTextAttributes = [
238+
private const EN_TEXT_ATTRIBUTES = [
239239
self::DECIMAL => ['', '', '-', '', ' ', 'XXX', ''],
240240
self::CURRENCY => ['¤', '', '', '', ' ', 'XXX'],
241241
];
@@ -263,8 +263,8 @@ public function __construct(?string $locale = 'en', int $style = null, string $p
263263
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'locale', $locale, 'Only the locale "en" is supported');
264264
}
265265

266-
if (!\in_array($style, self::$supportedStyles)) {
267-
$message = sprintf('The available styles are: %s.', implode(', ', array_keys(self::$supportedStyles)));
266+
if (!\in_array($style, self::SUPPORTED_STYLES)) {
267+
$message = sprintf('The available styles are: %s.', implode(', ', array_keys(self::SUPPORTED_STYLES)));
268268
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'style', $style, $message);
269269
}
270270

@@ -463,7 +463,7 @@ public function getPattern()
463463
*/
464464
public function getSymbol(int $attr)
465465
{
466-
return \array_key_exists($this->style, self::$enSymbols) && \array_key_exists($attr, self::$enSymbols[$this->style]) ? self::$enSymbols[$this->style][$attr] : false;
466+
return \array_key_exists($this->style, self::EN_SYMBOLS) && \array_key_exists($attr, self::EN_SYMBOLS[$this->style]) ? self::EN_SYMBOLS[$this->style][$attr] : false;
467467
}
468468

469469
/**
@@ -477,7 +477,7 @@ public function getSymbol(int $attr)
477477
*/
478478
public function getTextAttribute(int $attr)
479479
{
480-
return \array_key_exists($this->style, self::$enTextAttributes) && \array_key_exists($attr, self::$enTextAttributes[$this->style]) ? self::$enTextAttributes[$this->style][$attr] : false;
480+
return \array_key_exists($this->style, self::EN_TEXT_ATTRIBUTES) && \array_key_exists($attr, self::EN_TEXT_ATTRIBUTES[$this->style]) ? self::EN_TEXT_ATTRIBUTES[$this->style][$attr] : false;
481481
}
482482

483483
/**
@@ -571,29 +571,29 @@ public function parse(string $value, int $type = self::TYPE_DOUBLE, int &$positi
571571
*/
572572
public function setAttribute(int $attr, int $value)
573573
{
574-
if (!\in_array($attr, self::$supportedAttributes)) {
574+
if (!\in_array($attr, self::SUPPORTED_ATTRIBUTES)) {
575575
$message = sprintf(
576576
'The available attributes are: %s',
577-
implode(', ', array_keys(self::$supportedAttributes))
577+
implode(', ', array_keys(self::SUPPORTED_ATTRIBUTES))
578578
);
579579

580580
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'attr', $value, $message);
581581
}
582582

583-
if (self::$supportedAttributes['ROUNDING_MODE'] === $attr && $this->isInvalidRoundingMode($value)) {
583+
if (self::SUPPORTED_ATTRIBUTES['ROUNDING_MODE'] === $attr && $this->isInvalidRoundingMode($value)) {
584584
$message = sprintf(
585585
'The supported values for ROUNDING_MODE are: %s',
586-
implode(', ', array_keys(self::$roundingModes))
586+
implode(', ', array_keys(self::ROUNDING_MODES))
587587
);
588588

589589
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'attr', $value, $message);
590590
}
591591

592-
if (self::$supportedAttributes['GROUPING_USED'] === $attr) {
592+
if (self::SUPPORTED_ATTRIBUTES['GROUPING_USED'] === $attr) {
593593
$value = $this->normalizeGroupingUsedValue($value);
594594
}
595595

596-
if (self::$supportedAttributes['FRACTION_DIGITS'] === $attr) {
596+
if (self::SUPPORTED_ATTRIBUTES['FRACTION_DIGITS'] === $attr) {
597597
$value = $this->normalizeFractionDigitsValue($value);
598598
if ($value < 0) {
599599
// ignore negative values but do not raise an error
@@ -710,9 +710,9 @@ private function round($value, int $precision)
710710
$precision = $this->getUninitializedPrecision($value, $precision);
711711

712712
$roundingModeAttribute = $this->getAttribute(self::ROUNDING_MODE);
713-
if (isset(self::$phpRoundingMap[$roundingModeAttribute])) {
714-
$value = round($value, $precision, self::$phpRoundingMap[$roundingModeAttribute]);
715-
} elseif (isset(self::$customRoundingList[$roundingModeAttribute])) {
713+
if (isset(self::PHP_ROUNDING_MAP[$roundingModeAttribute])) {
714+
$value = round($value, $precision, self::PHP_ROUNDING_MAP[$roundingModeAttribute]);
715+
} elseif (isset(self::CUSTOM_ROUNDING_LIST[$roundingModeAttribute])) {
716716
$roundingCoef = 10 ** $precision;
717717
$value *= $roundingCoef;
718718
$value = (float) (string) $value;
@@ -836,7 +836,7 @@ private function getInt64Value($value)
836836
*/
837837
private function isInvalidRoundingMode(int $value): bool
838838
{
839-
if (\in_array($value, self::$roundingModes, true)) {
839+
if (\in_array($value, self::ROUNDING_MODES, true)) {
840840
return false;
841841
}
842842

0 commit comments

Comments
 (0)