Skip to content

Commit c4f893a

Browse files
Merge branch '4.3' into 4.4
* 4.3: [Intl] use strict comparisons Fix s-maxage=3 transient test
2 parents 4ce8f19 + 21de9b9 commit c4f893a

File tree

5 files changed

+41
-31
lines changed

5 files changed

+41
-31
lines changed

DateFormatter/DateFormat/Hour1200Transformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Hour1200Transformer extends HourTransformer
2626
public function format(\DateTime $dateTime, int $length): string
2727
{
2828
$hourOfDay = $dateTime->format('g');
29-
$hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay;
29+
$hourOfDay = '12' === $hourOfDay ? '0' : $hourOfDay;
3030

3131
return $this->padLeft($hourOfDay, $length);
3232
}

DateFormatter/DateFormat/Hour2400Transformer.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ public function format(\DateTime $dateTime, int $length): string
3333
*/
3434
public function normalizeHour(int $hour, string $marker = null): int
3535
{
36-
if ('AM' == $marker) {
36+
$marker = (string) $marker;
37+
38+
if ('AM' === $marker) {
3739
$hour = 0;
38-
} elseif ('PM' == $marker) {
40+
} elseif ('PM' === $marker) {
3941
$hour = 12;
4042
}
4143

DateFormatter/DateFormat/Hour2401Transformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Hour2401Transformer extends HourTransformer
2626
public function format(\DateTime $dateTime, int $length): string
2727
{
2828
$hourOfDay = $dateTime->format('G');
29-
$hourOfDay = ('0' == $hourOfDay) ? '24' : $hourOfDay;
29+
$hourOfDay = '0' === $hourOfDay ? '24' : $hourOfDay;
3030

3131
return $this->padLeft($hourOfDay, $length);
3232
}
@@ -36,7 +36,7 @@ public function format(\DateTime $dateTime, int $length): string
3636
*/
3737
public function normalizeHour(int $hour, string $marker = null): int
3838
{
39-
if ((null === $marker && 24 === $hour) || 'AM' == $marker) {
39+
if ((null === $marker && 24 == $hour) || 'AM' == $marker) {
4040
$hour = 0;
4141
} elseif ('PM' == $marker) {
4242
$hour = 12;

DateFormatter/DateFormat/TimezoneTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function getEtcTimeZoneId($formattedTimeZone)
102102
if (preg_match('/GMT(?P<signal>[+-])(?P<hours>\d{2}):?(?P<minutes>\d{2})/', $formattedTimeZone, $matches)) {
103103
$hours = (int) $matches['hours'];
104104
$minutes = (int) $matches['minutes'];
105-
$signal = '-' == $matches['signal'] ? '+' : '-';
105+
$signal = '-' === $matches['signal'] ? '+' : '-';
106106

107107
if (0 < $minutes) {
108108
throw new NotImplementedException(sprintf('It is not possible to use a GMT time zone with minutes offset different than zero (0). GMT time zone tried: %s.', $formattedTimeZone));

NumberFormatter/NumberFormatter.php

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,19 @@ public function __construct(?string $locale = 'en', int $style = null, $pattern
272272
throw new MethodArgumentNotImplementedException(__METHOD__, 'pattern');
273273
}
274274

275-
$this->style = $style;
275+
$this->style = null !== $style ? (int) $style : null;
276276
}
277277

278278
/**
279279
* Static constructor.
280280
*
281-
* @param string $locale The locale code. The only supported locale is "en" (or null using the default locale, i.e. "en")
282-
* @param int $style Style of the formatting, one of the format style constants.
283-
* The only currently supported styles are NumberFormatter::DECIMAL
284-
* and NumberFormatter::CURRENCY.
285-
* @param string $pattern Not supported. A pattern string in case $style is NumberFormat::PATTERN_DECIMAL or
286-
* NumberFormat::PATTERN_RULEBASED. It must conform to the syntax
287-
* described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation
281+
* @param string|null $locale The locale code. The only supported locale is "en" (or null using the default locale, i.e. "en")
282+
* @param int $style Style of the formatting, one of the format style constants.
283+
* The only currently supported styles are NumberFormatter::DECIMAL
284+
* and NumberFormatter::CURRENCY.
285+
* @param string $pattern Not supported. A pattern string in case $style is NumberFormat::PATTERN_DECIMAL or
286+
* NumberFormat::PATTERN_RULEBASED. It must conform to the syntax
287+
* described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation
288288
*
289289
* @return self
290290
*
@@ -314,7 +314,7 @@ public static function create($locale = 'en', $style = null, $pattern = null)
314314
*/
315315
public function formatCurrency($value, $currency)
316316
{
317-
if (self::DECIMAL == $this->style) {
317+
if (self::DECIMAL === $this->style) {
318318
return $this->format($value);
319319
}
320320

@@ -353,19 +353,21 @@ public function formatCurrency($value, $currency)
353353
*/
354354
public function format($value, $type = self::TYPE_DEFAULT)
355355
{
356+
$type = (int) $type;
357+
356358
// The original NumberFormatter does not support this format type
357-
if (self::TYPE_CURRENCY == $type) {
359+
if (self::TYPE_CURRENCY === $type) {
358360
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
359361

360362
return false;
361363
}
362364

363-
if (self::CURRENCY == $this->style) {
365+
if (self::CURRENCY === $this->style) {
364366
throw new NotImplementedException(sprintf('%s() method does not support the formatting of currencies (instance with CURRENCY style). %s', __METHOD__, NotImplementedException::INTL_INSTALL_MESSAGE));
365367
}
366368

367369
// Only the default type is supported.
368-
if (self::TYPE_DEFAULT != $type) {
370+
if (self::TYPE_DEFAULT !== $type) {
369371
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'type', $type, 'Only TYPE_DEFAULT is supported');
370372
}
371373

@@ -385,7 +387,7 @@ public function format($value, $type = self::TYPE_DEFAULT)
385387
*
386388
* @param int $attr An attribute specifier, one of the numeric attribute constants
387389
*
388-
* @return bool|int The attribute value on success or false on error
390+
* @return int|false The attribute value on success or false on error
389391
*
390392
* @see https://php.net/numberformatter.getattribute
391393
*/
@@ -438,7 +440,7 @@ public function getLocale($type = Locale::ACTUAL_LOCALE)
438440
/**
439441
* Not supported. Returns the formatter's pattern.
440442
*
441-
* @return bool|string The pattern string used by the formatter or false on error
443+
* @return string|false The pattern string used by the formatter or false on error
442444
*
443445
* @see https://php.net/numberformatter.getpattern
444446
*
@@ -454,7 +456,7 @@ public function getPattern()
454456
*
455457
* @param int $attr A symbol specifier, one of the format symbol constants
456458
*
457-
* @return bool|string The symbol value or false on error
459+
* @return string|false The symbol value or false on error
458460
*
459461
* @see https://php.net/numberformatter.getsymbol
460462
*/
@@ -468,7 +470,7 @@ public function getSymbol($attr)
468470
*
469471
* @param int $attr An attribute specifier, one of the text attribute constants
470472
*
471-
* @return bool|string The attribute value or false on error
473+
* @return string|false The attribute value or false on error
472474
*
473475
* @see https://php.net/numberformatter.gettextattribute
474476
*/
@@ -484,7 +486,7 @@ public function getTextAttribute($attr)
484486
* @param string $currency Parameter to receive the currency name (reference)
485487
* @param int $position Offset to begin the parsing on return this value will hold the offset at which the parsing ended
486488
*
487-
* @return bool|string The parsed numeric value or false on error
489+
* @return float|false The parsed numeric value or false on error
488490
*
489491
* @see https://php.net/numberformatter.parsecurrency
490492
*
@@ -508,7 +510,9 @@ public function parseCurrency($value, &$currency, &$position = null)
508510
*/
509511
public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0)
510512
{
511-
if (self::TYPE_DEFAULT == $type || self::TYPE_CURRENCY == $type) {
513+
$type = (int) $type;
514+
515+
if (self::TYPE_DEFAULT === $type || self::TYPE_CURRENCY === $type) {
512516
trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING);
513517

514518
return false;
@@ -565,6 +569,8 @@ public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0)
565569
*/
566570
public function setAttribute($attr, $value)
567571
{
572+
$attr = (int) $attr;
573+
568574
if (!\in_array($attr, self::$supportedAttributes)) {
569575
$message = sprintf(
570576
'The available attributes are: %s',
@@ -574,7 +580,7 @@ public function setAttribute($attr, $value)
574580
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'attr', $value, $message);
575581
}
576582

577-
if (self::$supportedAttributes['ROUNDING_MODE'] == $attr && $this->isInvalidRoundingMode($value)) {
583+
if (self::$supportedAttributes['ROUNDING_MODE'] === $attr && $this->isInvalidRoundingMode($value)) {
578584
$message = sprintf(
579585
'The supported values for ROUNDING_MODE are: %s',
580586
implode(', ', array_keys(self::$roundingModes))
@@ -583,11 +589,11 @@ public function setAttribute($attr, $value)
583589
throw new MethodArgumentValueNotImplementedException(__METHOD__, 'attr', $value, $message);
584590
}
585591

586-
if (self::$supportedAttributes['GROUPING_USED'] == $attr) {
592+
if (self::$supportedAttributes['GROUPING_USED'] === $attr) {
587593
$value = $this->normalizeGroupingUsedValue($value);
588594
}
589595

590-
if (self::$supportedAttributes['FRACTION_DIGITS'] == $attr) {
596+
if (self::$supportedAttributes['FRACTION_DIGITS'] === $attr) {
591597
$value = $this->normalizeFractionDigitsValue($value);
592598
if ($value < 0) {
593599
// ignore negative values but do not raise an error
@@ -751,7 +757,7 @@ private function formatNumber($value, int $precision): string
751757
*/
752758
private function getUninitializedPrecision($value, int $precision): int
753759
{
754-
if (self::CURRENCY == $this->style) {
760+
if (self::CURRENCY === $this->style) {
755761
return $precision;
756762
}
757763

@@ -782,11 +788,13 @@ private function isInitializedAttribute(string $attr): bool
782788
*/
783789
private function convertValueDataType($value, int $type)
784790
{
785-
if (self::TYPE_DOUBLE == $type) {
791+
$type = (int) $type;
792+
793+
if (self::TYPE_DOUBLE === $type) {
786794
$value = (float) $value;
787-
} elseif (self::TYPE_INT32 == $type) {
795+
} elseif (self::TYPE_INT32 === $type) {
788796
$value = $this->getInt32Value($value);
789-
} elseif (self::TYPE_INT64 == $type) {
797+
} elseif (self::TYPE_INT64 === $type) {
790798
$value = $this->getInt64Value($value);
791799
}
792800

0 commit comments

Comments
 (0)