8000 Merge branch '3.4' into 4.3 · symfony/symfony@38f08ba · GitHub
[go: up one dir, main page]

Skip to content

Commit 38f08ba

Browse files
Merge branch '3.4' into 4.3
* 3.4: [Intl] use strict comparisons Fix s-maxage=3 transient test
2 parents fdf6fc3 + 02a90d2 commit 38f08ba

File tree

6 files changed

+48
-38
lines changed

6 files changed

+48
-38
lines changed

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,15 +660,15 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
660660
$this->assertTraceContains('miss');
661661
$this->assertTraceContains('store');
662662
$this->assertEquals('Hello World', $this->response->getContent());
663-
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
663+
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
664664

665665
$this->request('GET', '/');
666666
$this->assertHttpKernelIsNotCalled();
667667
$this->assertEquals(200, $this->response->getStatusCode());
668668
$this->assertTraceContains('fresh');
669669
$this->assertTraceNotContains('store');
670670
$this->assertEquals('Hello World', $this->response->getContent());
671-
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
671+
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
672672

673673
// expires the cache
674674
$values = $this->getMetaStorageValues();
@@ -688,7 +688,7 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
688688
$this->assertTraceContains('invalid');
689689
$this->assertTraceContains('store');
690690
$this->assertEquals('Hello World', $this->response->getContent());
691-
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
691+
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
692692

693693
$this->setNextResponse();
694694

@@ -698,7 +698,7 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
698698
$this->assertTraceContains('fresh');
699699
$this->assertTraceNotContains('store');
700700
$this->assertEquals('Hello World', $this->response->getContent());
701-
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
701+
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
702702
}
703703

704704
public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpiredWithStatus304()
@@ -711,7 +711,7 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
711711
$this->assertTraceContains('miss');
712712
$this->assertTraceContains('store');
713713
$this->assertEquals('Hello World', $this->response->getContent());
714-
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
714+
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
715715

716716
$this->request('GET', '/');
717717
$this->assertHttpKernelIsNotCalled();
@@ -739,15 +739,15 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
739739
$this->assertTraceContains('store');
740740
$this->assertTraceNotContains('miss');
741741
$this->assertEquals('Hello World', $this->response->getContent());
742-
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
742+
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
743743

744744
$this->request('GET', '/');
745745
$this->assertHttpKernelIsNotCalled();
746746
$this->assertEquals(200, $this->response->getStatusCode());
747747
$this->assertTraceContains('fresh');
748748
$this->assertTraceNotContains('store');
749749
$this->assertEquals('Hello World', $this->response->getContent());
750-
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));
750+
$this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control'));
751751
}
752752

753753
public function testDoesNotAssignDefaultTtlWhenResponseHasMustRevalidateDirective()

src/Symfony/Component/Intl/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
}

src/Symfony/Component/Intl/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

src/Symfony/Component/Intl/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;

src/Symfony/Component/Intl/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));

src/Symfony/Component/Intl/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
@@ -763,7 +769,7 @@ private function formatNumber($value, $precision)
763769
*/
764770
private function getUninitializedPrecision($value, $precision)
765771
{
766-
if (self::CURRENCY == $this->style) {
772+
if (self::CURRENCY === $this->style) {
767773
return $precision;
768774
}
769775

@@ -799,11 +805,13 @@ private function isInitializedAttribute($attr)
799805
*/
800806
private function convertValueDataType($value, $type)
801807
{
802-
if (self::TYPE_DOUBLE == $type) {
808+
$type = (int) $type;
809+
810+
if (self::TYPE_DOUBLE === $type) {
803811
$value = (float) $value;
804-
} elseif (self::TYPE_INT32 == $type) {
812+
} elseif (self::TYPE_INT32 === $type) {
805813
$value = $this->getInt32Value($value);
806-
} elseif (self::TYPE_INT64 == $type) {
814+
} elseif (self::TYPE_INT64 === $type) {
807815
$value = $this->getInt64Value($value);
808816
}
809817

0 commit comments

Comments
 (0)
0