Skip to content

Commit 721a605

Browse files
committed
feature #47730 Ban DateTime from the codebase (WebMamba)
This PR was squashed before being merged into the 6.2 branch. Discussion ---------- Ban DateTime from the codebase | Q | A | ------------- | --- | Branch? | 6.2 | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | #47580 | License | MIT | Doc PR | symfony As discuss in this issue, the purpose of this PR is to remove DateTime from the code base in favor to DateTimeImmutable. I will process it component by component. Feel free to discuss! Commits ------- 689385a83f Ban DateTime from the codebase
2 parents 6184ccb + bcfb62d commit 721a605

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

Tests/Fixtures/ReturnTyped.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public function getFoos(): array
2121
return 'It doesn\'t respect the return type on purpose';
2222
}
2323

24-
public function addFoo(\DateTime $dateTime)
24+
public function addFoo(\DateTimeImmutable $dateTime)
2525
{
2626
}
2727

28-
public function removeFoo(\DateTime $dateTime)
28+
public function removeFoo(\DateTimeImmutable $dateTime)
2929
{
3030
}
3131

Tests/Fixtures/TestClassTypeErrorInsideCall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class TestClassTypeErrorInsideCall
1515
{
16-
public function expectsDateTime(\DateTime $date)
16+
public function expectsDateTime(\DateTimeImmutable $date)
1717
{
1818
}
1919

Tests/Fixtures/TypeHinted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TypeHinted
2323
*/
2424
private $countable;
2525

26-
public function setDate(\DateTime $date)
26+
public function setDate(\DateTimeImmutable $date)
2727
{
2828
$this->date = $date;
2929
}

Tests/PropertyAccessorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,24 +632,24 @@ public function testIsWritableForReferenceChainIssue($object, $path, $value)
632632
public function testThrowTypeError()
633633
{
634634
$this->expectException(InvalidArgumentException::class);
635-
$this->expectExceptionMessage('Expected argument of type "DateTime", "string" given at property path "date"');
635+
$this->expectExceptionMessage('Expected argument of type "DateTimeImmutable", "string" given at property path "date"');
636636
$object = new TypeHinted();
637637

638-
$this->propertyAccessor->setValue($object, 'date', 'This is a string, \DateTime expected.');
638+
$this->propertyAccessor->setValue($object, 'date', 'This is a string, \DateTimeImmutable expected.');
639639
}
640640

641641
public function testThrowTypeErrorWithNullArgument()
642642
{
643643
$this->expectException(InvalidArgumentException::class);
644-
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
644+
$this->expectExceptionMessage('Expected argument of type "DateTimeImmutable", "null" given');
645645
$object = new TypeHinted();
646646

647647
$this->propertyAccessor->setValue($object, 'date', null);
648648
}
649649

650650
public function testSetTypeHint()
651651
{
652-
$date = new \DateTime();
652+
$date = new \DateTimeImmutable();
653653
$object = new TypeHinted();
654654

655655
$this->propertyAccessor->setValue($object, 'date', $date);
@@ -774,7 +774,7 @@ public function testDoNotDiscardReturnTypeError()
774774
$this->expectException(\TypeError::class);
775775
$object = new ReturnTyped();
776776

777-
$this->propertyAccessor->setValue($object, 'foos', [new \DateTime()]);
777+
$this->propertyAccessor->setValue($object, 'foos', [new \DateTimeImmutable()]);
778778
}
779779

780780
public function testDoNotDiscardReturnTypeErrorWhenWriterMethodIsMisconfigured()

0 commit comments

Comments
 (0)