Skip to content

Commit 1cfe3bc

Browse files
Merge branch '5.2' into 5.x
* 5.2: Changed private static array-properties to const
2 parents 2b9e693 + 77e720d commit 1cfe3bc

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
@@ -42,7 +42,7 @@ abstract class IntlGlobals
4242
/**
4343
* All known error codes.
4444
*/
45-
private static $errorCodes = [
45+
private const ERROR_CODES = [
4646
self::U_ZERO_ERROR => 'U_ZERO_ERROR',
4747
self::U_ILLEGAL_ARGUMENT_ERROR => 'U_ILLEGAL_ARGUMENT_ERROR',
4848
self::U_PARSE_ERROR => 'U_PARSE_ERROR',
@@ -71,7 +71,7 @@ public static function isFailure(int $errorCode): bool
7171

7272
trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.');
7373

74-
return isset(self::$errorCodes[$errorCode])
74+
return isset(self::ERROR_CODES[$errorCode])
7575
&& $errorCode > self::U_ZERO_ERROR;
7676
}
7777

@@ -122,7 +122,7 @@ public static function getErrorName(int $code): string
122122

123123
trigger_deprecation('symfony/intl', '5.3', 'Polyfills are deprecated, try running "composer require symfony/polyfill-intl-icu ^1.21" instead.');
124124

125-
return self::$errorCodes[$code] ?? '[BOGUS UErrorCode]';
125+
return self::ERROR_CODES[$code] ?? '[BOGUS UErrorCode]';
126126
}
127127

128128
/**
@@ -139,11 +139,11 @@ public static function setError(int $code, string $message = '')
139139
return Icu::setError($code, $message);
140140
}
141141

142-
if (!isset(self::$errorCodes[$code])) {
142+
if (!isset(self::ERROR_CODES[$code])) {
143143
throw new \InvalidArgumentException(sprintf('No such error code: "%s".', $code));
144144
}
145145

146-
self::$errorMessage = $message ? sprintf('%s: %s', $message, self::$errorCodes[$code]) : self::$errorCodes[$code];
146+
self::$errorMessage = $message ? sprintf('%s: %s', $message, self::ERROR_CODES[$code]) : self::ERROR_CODES[$code];
147147
self::$errorCode = $code;
148148
}
149149
}

NumberFormatter/NumberFormatter.php

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

175175
/**
176176
* Supported attributes to the setAttribute() $attr argument.
177177
*/
178-
private static $supportedAttributes = [
178+
private const SUPPORTED_ATTRIBUTES = [
179179
'FRACTION_DIGITS' => self::FRACTION_DIGITS,
180180
'GROUPING_USED' => self::GROUPING_USED,
181181
'ROUNDING_MODE' => self::ROUNDING_MODE,
@@ -186,7 +186,7 @@ abstract class NumberFormatter
186186
* NumberFormatter::ROUNDING_MODE. NumberFormatter::ROUND_DOWN
187187
* and NumberFormatter::ROUND_UP does not have a PHP only equivalent.
188188
*/
189-
private static $roundingModes = [
189+
private const ROUNDING_MODES = [
190190
'ROUND_HALFEVEN' => self::ROUND_HALFEVEN,
191191
'ROUND_HALFDOWN' => self::ROUND_HALFDOWN,
192192
'ROUND_HALFUP' => self::ROUND_HALFUP,
@@ -202,7 +202,7 @@ abstract class NumberFormatter
202202
*
203203
* @see https://php.net/round
204204
*/
205-
private static $phpRoundingMap = [
205+
private const PHP_ROUNDING_MAP = [
206206
self::ROUND_HALFDOWN => \PHP_ROUND_HALF_DOWN,
207207
self::ROUND_HALFEVEN => \PHP_ROUND_HALF_EVEN,
208208
self::ROUND_HALFUP => \PHP_ROUND_HALF_UP,
@@ -213,7 +213,7 @@ abstract class NumberFormatter
213213
* PHP's round() function, but there's an equivalent. Keys are rounding
214214
* modes, values does not matter.
215215
*/
216-
private static $customRoundingList = [
216+
private const CUSTOM_ROUNDING_LIST = [
217217
self::ROUND_CEILING => true,
218218
self::ROUND_FLOOR => true,
219219
self::ROUND_DOWN => true,
@@ -232,12 +232,12 @@ abstract class NumberFormatter
232232
*/
233233
private static $int64Max = 9223372036854775807;
234234

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

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

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

@@ -465,7 +465,7 @@ public function getPattern()
465465
*/
466466
public function getSymbol(int $attr)
467467
{
468-
return \array_key_exists($this->style, self::$enSymbols) && \array_key_exists($attr, self::$enSymbols[$this->style]) ? self::$enSymbols[$this->style][$attr] : false;
468+
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;
469469
}
470470

471471
/**
@@ -479,7 +479,7 @@ public function getSymbol(int $attr)
479479
*/
480480
public function getTextAttribute(int $attr)
481481
{
482-
return \array_key_exists($this->style, self::$enTextAttributes) && \array_key_exists($attr, self::$enTextAttributes[$this->style]) ? self::$enTextAttributes[$this->style][$attr] : false;
482+
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;
483483
}
484484

485485
/**
@@ -573,29 +573,29 @@ public function parse(string $value, int $type = self::TYPE_DOUBLE, int &$positi
573573
*/
574574
public function setAttribute(int $attr, int $value)
575575
{
576-
if (!\in_array($attr, self::$supportedAttributes)) {
576+
if (!\in_array($attr, self::SUPPORTED_ATTRIBUTES)) {
577577
$message = sprintf(
578578
'The available attributes are: %s',
579-
implode(', ', array_keys(self::$supportedAttributes))
579+
implode(', ', array_keys(self::SUPPORTED_ATTRIBUTES))
580580
);
581581

582582
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'attr', $value, $message);
583583
}
584584

585-
if (self::$supportedAttributes['ROUNDING_MODE'] === $attr && $this->isInvalidRoundingMode($value)) {
585+
if (self::SUPPORTED_ATTRIBUTES['ROUNDING_MODE'] === $attr && $this->isInvalidRoundingMode($value)) {
586586
$message = sprintf(
587587
'The supported values for ROUNDING_MODE are: %s',
588-
implode(', ', array_keys(self::$roundingModes))
588+
implode(', ', array_keys(self::ROUNDING_MODES))
589589
);
590590

591591
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'attr', $value, $message);
592592
}
593593

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

598-
if (self::$supportedAttributes['FRACTION_DIGITS'] === $attr) {
598+
if (self::SUPPORTED_ATTRIBUTES['FRACTION_DIGITS'] === $attr) {
599599
$value = $this->normalizeFractionDigitsValue($value);
600600
if ($value < 0) {
601601
// ignore negative values but do not raise an error
@@ -712,9 +712,9 @@ private function round($value, int $precision)
712712
$precision = $this->getUninitializedPrecision($value, $precision);
713713

714714
$roundingModeAttribute = $this->getAttribute(self::ROUNDING_MODE);
715-
if (isset(self::$phpRoundingMap[$roundingModeAttribute])) {
716-
$value = round($value, $precision, self::$phpRoundingMap[$roundingModeAttribute]);
717-
} elseif (isset(self::$customRoundingList[$roundingModeAttribute])) {
715+
if (isset(self::PHP_ROUNDING_MAP[$roundingModeAttribute])) {
716+
$value = round($value, $precision, self::PHP_ROUNDING_MAP[$roundingModeAttribute]);
717+
} elseif (isset(self::CUSTOM_ROUNDING_LIST[$roundingModeAttribute])) {
718718
$roundingCoef = 10 ** $precision;
719719
$value *= $roundingCoef;
720720
$value = (float) (string) $value;
@@ -838,7 +838,7 @@ private function getInt64Value($value)
838838
*/
839839
private function isInvalidRoundingMode(int $value): bool
840840
{
841-
if (\in_array($value, self::$roundingModes, true)) {
841+
if (\in_array($value, self::ROUNDING_MODES, true)) {
842842
return false;
843843
}
844844

0 commit comments

Comments
 (0)