8000 minor #18751 [3.0] Fixed DateTimeInterface comparison (francisbesset) · symfony/symfony@6aa00aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 6aa00aa

Browse files
committed
minor #18751 [3.0] Fixed DateTimeInterface comparison (francisbesset)
This PR was merged into the 3.0 branch. Discussion ---------- [3.0] Fixed DateTimeInterface comparison | Q | A | ------------- | --- | Branch? | 3.0 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | DateTime class implements the DateTimeInterface. It is useless to compare is a value is an instance of DateTime or DateTimeInterface. Commits ------- 9a0bc99 Fixed DateTimeInterface comparaison
2 parents be8a0b1 + 9a0bc99 commit 6aa00aa

10 files changed

+17
-17
lines changed

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToArrayTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function transform($dateTime)
7272
), array_flip($this->fields));
7373
}
7474

75-
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
76-
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
75+
if (!$dateTime instanceof \DateTimeInterface) {
76+
throw new TransformationFailedException('Expected a \DateTimeInterface.');
7777
}
7878

7979
if ($this->inputTimezone !== $this->outputTimezone) {

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public function transform($dateTime)
8484
return '';
8585
}
8686

87-
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
88-
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
87+
if (!$dateTime instanceof \DateTimeInterface) {
88+
throw new TransformationFailedException('Expected a \DateTimeInterface.');
8989
}
9090

9191
$value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToRfc3339Transformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public function transform($dateTime)
2727
return '';
2828
}
2929

30-
if (!$dateTime instanceof \DateTime && !$dateTime instanceof \DateTimeInterface) {
31-
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
30+
if (!$dateTime instanceof \DateTimeInterface) {
31+
throw new TransformationFailedException('Expected a \DateTimeInterface.');
3232
}
3333

3434
if ($this->inputTimezone !== $this->outputTimezone) {

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToStringTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public function transform($value)
9999
return '';
100100
}
101101

102-
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
103-
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
102+
if (!$value instanceof \DateTimeInterface) {
103+
throw new TransformationFailedException('Expected a \DateTimeInterface.');
104104
}
105105

106106
if (!$value instanceof \DateTimeImmutable) {

src/Symfony/Component/Form/Extension/Core/DataTransformer/DateTimeToTimestampTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function transform($value)
3838
return;
3939
}
4040

41-
if (!$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
42-
throw new TransformationFailedException('Expected a \DateTime or \DateTimeInterface.');
41+
if (!$value instanceof \DateTimeInterface) {
42+
throw new TransformationFailedException('Expected a \DateTimeInterface.');
4343
}
4444

4545
return $value->getTimestamp();

src/Symfony/Component/HttpFoundation/Cookie.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct($name, $value = null, $expire = 0, $path = '/', $dom
5151
}
5252

5353
// convert expiration time to a Unix timestamp
54-
if ($expire instanceof \DateTime || $expire instanceof \DateTimeInterface) {
54+
if ($expire instanceof \DateTimeInterface) {
5555
$expire = $expire->format('U');
5656
} elseif (!is_numeric($expire)) {
5757
$expire = strtotime($expire);

src/Symfony/Component/HttpKernel/DataCollector/Util/ValueExporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ValueExporter
2828
public function exportValue($value, $depth = 1, $deep = false)
2929
{
3030
if (is_object($value)) {
31-
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
31+
if ($value instanceof \DateTimeInterface) {
3232
return sprintf('Object(%s) - %s', get_class($value), $value->format(\DateTime::ISO8601));
3333
}
3434

src/Symfony/Component/Validator/ConstraintValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected function formatTypeOf($value)
7272
* (i.e. "false" for false, "1" for 1 etc.). Strings are always wrapped
7373
* in double quotes ("). Objects, arrays and resources are formatted as
7474
* "object", "array" and "resource". If the $format bitmask contains
75-
* the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted
75+
* the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted
7676
* as RFC-3339 dates ("Y-m-d H:i:s").
7777
*
7878
* Be careful when passing message parameters to a constraint violation
@@ -89,7 +89,7 @@ protected function formatTypeOf($value)
8989
*/
9090
protected function formatValue($value, $format = 0)
9191
{
92-
$isDateTime = $value instanceof \DateTime || $value instanceof \DateTimeInterface;
92+
$isDateTime = $value instanceof \DateTimeInterface;
9393

9494
if (($format & self::PRETTY_DATE) && $isDateTime) {
9595
if (class_exists('IntlDateFormatter')) {

src/Symfony/Component/Validator/Constraints/AbstractComparisonValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function validate($value, Constraint $constraint)
4747
// If $value is immutable, convert the compared value to a
4848
// DateTimeImmutable too
4949
$comparedValue = new \DatetimeImmutable($comparedValue);
50-
} elseif ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
50+
} elseif ($value instanceof \DateTimeInterface) {
5151
// Otherwise use DateTime
5252
$comparedValue = new \DateTime($comparedValue);
5353
}

src/Symfony/Component/Validator/Constraints/RangeValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function validate($value, Constraint $constraint)
3333
return;
3434
}
3535

36-
if (!is_numeric($value) && !$value instanceof \DateTime && !$value instanceof \DateTimeInterface) {
36+
if (!is_numeric($value) && !$value instanceof \DateTimeInterface) {
3737
$this->context->buildViolation($constraint->invalidMessage)
3838
->setParameter('{{ value }}', $this->formatValue($value, self::PRETTY_DATE))
3939
->setCode(Range::INVALID_CHARACTERS_ERROR)
@@ -49,7 +49,7 @@ public function validate($value, Constraint $constraint)
4949
// This allows to compare with any date/time value supported by
5050
// the DateTime constructor:
5151
// http://php.net/manual/en/datetime.formats.php
52-
if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) {
52+
if ($value instanceof \DateTimeInterface) {
5353
if (is_string($min)) {
5454
$min = new \DateTime($min);
5555
}

0 commit comments

Comments
 (0)
0