From d445465ef459b83ce2b9b4342bbb38fc9b8c1d02 Mon Sep 17 00:00:00 2001 From: Stefano Degenkamp Date: Wed, 12 Jun 2019 11:28:52 +0200 Subject: [PATCH] Fix binary operation `+`, `-` or `*` on string By type casting to integer. --- .../Component/Form/Extension/Core/Type/BirthdayType.php | 2 +- src/Symfony/Component/Form/Extension/Core/Type/DateType.php | 2 +- src/Symfony/Component/HttpFoundation/Response.php | 4 ++-- .../Component/HttpKernel/HttpCache/ResponseCacheStrategy.php | 2 +- .../Intl/DateFormatter/DateFormat/DayOfYearTransformer.php | 2 +- .../Intl/DateFormatter/DateFormat/FullTransformer.php | 2 +- src/Symfony/Component/Validator/Constraints/IssnValidator.php | 2 +- src/Symfony/Component/Validator/Constraints/LuhnValidator.php | 2 +- src/Symfony/Component/VarDumper/Caster/DateCaster.php | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php b/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php index 841bd0d85f..acb8d02b8c 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/BirthdayType.php @@ -21,7 +21,7 @@ class BirthdayType extends AbstractType */ public function configureOptions(OptionsResolver $resolver) { - $resolver->setDefault('years', range(date('Y') - 120, date('Y'))); + $resolver->setDefault('years', range((int) date('Y') - 120, date('Y'))); $resolver->setAllowedTypes('years', 'array'); } diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php index 09f5e1de5c..8ab5e9cc8a 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php @@ -256,7 +256,7 @@ class DateType extends AbstractType }; $resolver->setDefaults([ - 'years' => range(date('Y') - 5, date('Y') + 5), + 'years' => range((int) date('Y') - 5, (int) date('Y') + 5), 'months' => range(1, 12), 'days' => range(1, 31), 'widget' => 'choice', diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index b7d116259d..4ab05066f4 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -707,7 +707,7 @@ class Response return (int) $age; } - return max(time() - $this->getDate()->format('U'), 0); + return max(time() - (int) $this->getDate()->format('U'), 0); } /** @@ -788,7 +788,7 @@ class Response } if (null !== $this->getExpires()) { - return $this->getExpires()->format('U') - $this->getDate()->format('U'); + return (int) $this->getExpires()->format('U') - (int) $this->getDate()->format('U'); } } diff --git a/src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php b/src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php index 7037c497cc..25c071c335 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/ResponseCacheStrategy.php @@ -85,7 +85,7 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface $this->storeRelativeAgeDirective('s-maxage', $response->headers->getCacheControlDirective('s-maxage') ?: $response->headers->getCacheControlDirective('max-age'), $age); $expires = $response->getExpires(); - $expires = null !== $expires ? $expires->format('U') - $response->getDate()->format('U') : null; + $expires = null !== $expires ? (int) $expires->format('U') - (int) $response->getDate()->format('U') : null; $this->storeRelativeAgeDirective('expires', $expires >= 0 ? $expires : null, 0); } diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php index 8b48371f60..1443cc79ec 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/DayOfYearTransformer.php @@ -25,7 +25,7 @@ class DayOfYearTransformer extends Transformer */ public function format(\DateTime $dateTime, $length) { - $dayOfYear = $dateTime->format('z') + 1; + $dayOfYear = (int) $dateTime->format('z') + 1; return $this->padLeft($dayOfYear, $length); } diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php index 9c0d86ef05..13854ff719 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php @@ -315,7 +315,7 @@ class FullTransformer preg_match_all($this->regExp, $this->pattern, $matches); if (\in_array('yy', $matches[0])) { $dateTime->setTimestamp(time()); - $year = $year > $dateTime->format('y') + 20 ? 1900 + $year : 2000 + $year; + $year = $year > (int) $dateTime->format('y') + 20 ? 1900 + $year : 2000 + $year; } $dateTime->setDate($year, $month, $day); diff --git a/src/Symfony/Component/Validator/Constraints/IssnValidator.php b/src/Symfony/Component/Validator/Constraints/IssnValidator.php index f045e62e2c..41da39ebd8 100644 --- a/src/Symfony/Component/Validator/Constraints/IssnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/IssnValidator.php @@ -120,7 +120,7 @@ class IssnValidator extends ConstraintValidator for ($i = 0; $i < 7; ++$i) { // Multiply the first digit by 8, the second by 7, etc. - $checkSum += (8 - $i) * $canonical[$i]; + $checkSum += (8 - $i) * (int) $canonical[$i]; } if (0 !== $checkSum % 11) { diff --git a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php index 554fc6f48b..6e69f9ee74 100644 --- a/src/Symfony/Component/Validator/Constraints/LuhnValidator.php +++ b/src/Symfony/Component/Validator/Constraints/LuhnValidator.php @@ -83,7 +83,7 @@ class LuhnValidator extends ConstraintValidator // ^ ^ ^ ^ ^ // = 1+8 + 4 + 6 + 1+6 + 2 for ($i = $length - 2; $i >= 0; $i -= 2) { - $checkSum += array_sum(str_split($value[$i] * 2)); + $checkSum += array_sum(str_split((int) $value[$i] * 2)); } if (0 === $checkSum || 0 !== $checkSum % 10) { diff --git a/src/Symfony/Component/VarDumper/Caster/DateCaster.php b/src/Symfony/Component/VarDumper/Caster/DateCaster.php index 3b030b734a..40289a930b 100644 --- a/src/Symfony/Component/VarDumper/Caster/DateCaster.php +++ b/src/Symfony/Component/VarDumper/Caster/DateCaster.php @@ -95,7 +95,7 @@ class DateCaster if (3 === $i) { $now = new \DateTimeImmutable(); $dates[] = sprintf('%s more', ($end = $p->getEndDate()) - ? ceil(($end->format('U.u') - $d->format('U.u')) / ($now->add($p->getDateInterval())->format('U.u') - $now->format('U.u'))) + ? ceil(($end->format('U.u') - $d->format('U.u')) / ((int) $now->add($p->getDateInterval())->format('U.u') - (int) $now->format('U.u'))) : $p->recurrences - $i ); break;