From f019b5214d4df69b6ff5d8c9461ed801c1e9c2f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 8 Aug 2019 14:51:39 +0200 Subject: [PATCH 1/2] Fix s-maxage=3 transient test --- .../HttpKernel/Tests/HttpCache/HttpCacheTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index 7b3cac78c7..a50e09fb14 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -660,7 +660,7 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertTraceContains('miss'); $this->assertTraceContains('store'); $this->assertEquals('Hello World', $this->response->getContent()); - $this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control')); + $this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control')); $this->request('GET', '/'); $this->assertHttpKernelIsNotCalled(); @@ -668,7 +668,7 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertTraceContains('fresh'); $this->assertTraceNotContains('store'); $this->assertEquals('Hello World', $this->response->getContent()); - $this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control')); + $this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control')); // expires the cache $values = $this->getMetaStorageValues(); @@ -688,7 +688,7 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertTraceContains('invalid'); $this->assertTraceContains('store'); $this->assertEquals('Hello World', $this->response->getContent()); - $this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control')); + $this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control')); $this->setNextResponse(); @@ -698,7 +698,7 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertTraceContains('fresh'); $this->assertTraceNotContains('store'); $this->assertEquals('Hello World', $this->response->getContent()); - $this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control')); + $this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control')); } public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAfterTtlWasExpiredWithStatus304() @@ -711,7 +711,7 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertTraceContains('miss'); $this->assertTraceContains('store'); $this->assertEquals('Hello World', $this->response->getContent()); - $this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control')); + $this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control')); $this->request('GET', '/'); $this->assertHttpKernelIsNotCalled(); @@ -739,7 +739,7 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertTraceContains('store'); $this->assertTraceNotContains('miss'); $this->assertEquals('Hello World', $this->response->getContent()); - $this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control')); + $this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control')); $this->request('GET', '/'); $this->assertHttpKernelIsNotCalled(); @@ -747,7 +747,7 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertTraceContains('fresh'); $this->assertTraceNotContains('store'); $this->assertEquals('Hello World', $this->response->getContent()); - $this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control')); + $this->assertRegExp('/s-maxage=(2|3)/', $this->response->headers->get('Cache-Control')); } public function testDoesNotAssignDefaultTtlWhenResponseHasMustRevalidateDirective() From 02a90d2066d3a8c924a139a6cc4422d118179ae8 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Thu, 8 Aug 2019 18:50:30 +0200 Subject: [PATCH 2/2] [Intl] use strict comparisons --- .../DateFormat/Hour1200Transformer.php | 2 +- .../DateFormat/Hour2400Transformer.php | 6 +- .../DateFormat/Hour2401Transformer.php | 4 +- .../DateFormat/TimezoneTransformer.php | 2 +- .../Intl/NumberFormatter/NumberFormatter.php | 58 +++++++++++-------- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php index 157d242875..70cf965b28 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour1200Transformer.php @@ -26,7 +26,7 @@ class Hour1200Transformer extends HourTransformer public function format(\DateTime $dateTime, $length) { $hourOfDay = $dateTime->format('g'); - $hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay; + $hourOfDay = '12' === $hourOfDay ? '0' : $hourOfDay; return $this->padLeft($hourOfDay, $length); } diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php index 904a03691f..1904c958bf 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2400Transformer.php @@ -33,9 +33,11 @@ class Hour2400Transformer extends HourTransformer */ public function normalizeHour($hour, $marker = null) { - if ('AM' == $marker) { + $marker = (string) $marker; + + if ('AM' === $marker) { $hour = 0; - } elseif ('PM' == $marker) { + } elseif ('PM' === $marker) { $hour = 12; } diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php index e2988d852a..f289bd1295 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/Hour2401Transformer.php @@ -26,7 +26,7 @@ class Hour2401Transformer extends HourTransformer public function format(\DateTime $dateTime, $length) { $hourOfDay = $dateTime->format('G'); - $hourOfDay = ('0' == $hourOfDay) ? '24' : $hourOfDay; + $hourOfDay = '0' === $hourOfDay ? '24' : $hourOfDay; return $this->padLeft($hourOfDay, $length); } @@ -36,7 +36,7 @@ class Hour2401Transformer extends HourTransformer */ public function normalizeHour($hour, $marker = null) { - if ((null === $marker && 24 === $hour) || 'AM' == $marker) { + if ((null === $marker && 24 == $hour) || 'AM' == $marker) { $hour = 0; } elseif ('PM' == $marker) { $hour = 12; diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimezoneTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimezoneTransformer.php index 0b347c3930..e024951cb3 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimezoneTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/TimezoneTransformer.php @@ -102,7 +102,7 @@ class TimezoneTransformer extends Transformer if (preg_match('/GMT(?P[+-])(?P\d{2}):?(?P\d{2})/', $formattedTimeZone, $matches)) { $hours = (int) $matches['hours']; $minutes = (int) $matches['minutes']; - $signal = '-' == $matches['signal'] ? '+' : '-'; + $signal = '-' === $matches['signal'] ? '+' : '-'; if (0 < $minutes) { 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)); diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index 5ff5e35391..e0426b364b 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -272,19 +272,19 @@ class NumberFormatter throw new MethodArgumentNotImplementedException(__METHOD__, 'pattern'); } - $this->style = $style; + $this->style = null !== $style ? (int) $style : null; } /** * Static constructor. * - * @param string $locale The locale code. The only supported locale is "en" (or null using the default locale, i.e. "en") - * @param int $style Style of the formatting, one of the format style constants. - * The only currently supported styles are NumberFormatter::DECIMAL - * and NumberFormatter::CURRENCY. - * @param string $pattern Not supported. A pattern string in case $style is NumberFormat::PATTERN_DECIMAL or - * NumberFormat::PATTERN_RULEBASED. It must conform to the syntax - * described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation + * @param string|null $locale The locale code. The only supported locale is "en" (or null using the default locale, i.e. "en") + * @param int $style Style of the formatting, one of the format style constants. + * The only currently supported styles are NumberFormatter::DECIMAL + * and NumberFormatter::CURRENCY. + * @param string $pattern Not supported. A pattern string in case $style is NumberFormat::PATTERN_DECIMAL or + * NumberFormat::PATTERN_RULEBASED. It must conform to the syntax + * described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation * * @return self * @@ -314,7 +314,7 @@ class NumberFormatter */ public function formatCurrency($value, $currency) { - if (self::DECIMAL == $this->style) { + if (self::DECIMAL === $this->style) { return $this->format($value); } @@ -353,19 +353,21 @@ class NumberFormatter */ public function format($value, $type = self::TYPE_DEFAULT) { + $type = (int) $type; + // The original NumberFormatter does not support this format type - if (self::TYPE_CURRENCY == $type) { + if (self::TYPE_CURRENCY === $type) { trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING); return false; } - if (self::CURRENCY == $this->style) { + if (self::CURRENCY === $this->style) { throw new NotImplementedException(sprintf('%s() method does not support the formatting of currencies (instance with CURRENCY style). %s', __METHOD__, NotImplementedException::INTL_INSTALL_MESSAGE)); } // Only the default type is supported. - if (self::TYPE_DEFAULT != $type) { + if (self::TYPE_DEFAULT !== $type) { throw new MethodArgumentValueNotImplementedException(__METHOD__, 'type', $type, 'Only TYPE_DEFAULT is supported'); } @@ -385,7 +387,7 @@ class NumberFormatter * * @param int $attr An attribute specifier, one of the numeric attribute constants * - * @return bool|int The attribute value on success or false on error + * @return int|false The attribute value on success or false on error * * @see https://php.net/numberformatter.getattribute */ @@ -438,7 +440,7 @@ class NumberFormatter /** * Not supported. Returns the formatter's pattern. * - * @return bool|string The pattern string used by the formatter or false on error + * @return string|false The pattern string used by the formatter or false on error * * @see https://php.net/numberformatter.getpattern * @@ -454,7 +456,7 @@ class NumberFormatter * * @param int $attr A symbol specifier, one of the format symbol constants * - * @return bool|string The symbol value or false on error + * @return string|false The symbol value or false on error * * @see https://php.net/numberformatter.getsymbol */ @@ -468,7 +470,7 @@ class NumberFormatter * * @param int $attr An attribute specifier, one of the text attribute constants * - * @return bool|string The attribute value or false on error + * @return string|false The attribute value or false on error * * @see https://php.net/numberformatter.gettextattribute */ @@ -484,7 +486,7 @@ class NumberFormatter * @param string $currency Parameter to receive the currency name (reference) * @param int $position Offset to begin the parsing on return this value will hold the offset at which the parsing ended * - * @return bool|string The parsed numeric value or false on error + * @return float|false The parsed numeric value or false on error * * @see https://php.net/numberformatter.parsecurrency * @@ -508,7 +510,9 @@ class NumberFormatter */ public function parse($value, $type = self::TYPE_DOUBLE, &$position = 0) { - if (self::TYPE_DEFAULT == $type || self::TYPE_CURRENCY == $type) { + $type = (int) $type; + + if (self::TYPE_DEFAULT === $type || self::TYPE_CURRENCY === $type) { trigger_error(__METHOD__.'(): Unsupported format type '.$type, \E_USER_WARNING); return false; @@ -565,6 +569,8 @@ class NumberFormatter */ public function setAttribute($attr, $value) { + $attr = (int) $attr; + if (!\in_array($attr, self::$supportedAttributes)) { $message = sprintf( 'The available attributes are: %s', @@ -574,7 +580,7 @@ class NumberFormatter throw new MethodArgumentValueNotImplementedException(__METHOD__, 'attr', $value, $message); } - if (self::$supportedAttributes['ROUNDING_MODE'] == $attr && $this->isInvalidRoundingMode($value)) { + if (self::$supportedAttributes['ROUNDING_MODE'] === $attr && $this->isInvalidRoundingMode($value)) { $message = sprintf( 'The supported values for ROUNDING_MODE are: %s', implode(', ', array_keys(self::$roundingModes)) @@ -583,11 +589,11 @@ class NumberFormatter throw new MethodArgumentValueNotImplementedException(__METHOD__, 'attr', $value, $message); } - if (self::$supportedAttributes['GROUPING_USED'] == $attr) { + if (self::$supportedAttributes['GROUPING_USED'] === $attr) { $value = $this->normalizeGroupingUsedValue($value); } - if (self::$supportedAttributes['FRACTION_DIGITS'] == $attr) { + if (self::$supportedAttributes['FRACTION_DIGITS'] === $attr) { $value = $this->normalizeFractionDigitsValue($value); if ($value < 0) { // ignore negative values but do not raise an error @@ -763,7 +769,7 @@ class NumberFormatter */ private function getUninitializedPrecision($value, $precision) { - if (self::CURRENCY == $this->style) { + if (self::CURRENCY === $this->style) { return $precision; } @@ -799,11 +805,13 @@ class NumberFormatter */ private function convertValueDataType($value, $type) { - if (self::TYPE_DOUBLE == $type) { + $type = (int) $type; + + if (self::TYPE_DOUBLE === $type) { $value = (float) $value; - } elseif (self::TYPE_INT32 == $type) { + } elseif (self::TYPE_INT32 === $type) { $value = $this->getInt32Value($value); - } elseif (self::TYPE_INT64 == $type) { + } elseif (self::TYPE_INT64 === $type) { $value = $this->getInt64Value($value); }