Add #[NoDiscard] to CarbonImmutable modify(), next(), previous() and __call()
On PHP 8.5, DateTimeImmutable::modify() warns when its result is discarded, but CarbonImmutable overrides it and lost the attribute. Override modify(), next(), previous() and __call() in CarbonImmutable with #[NoDiscard] so a discarded result warns again. The attribute is ignored on older PHP versions, and mutable Carbon is unchanged. Existing immutable tests that discarded results now keep them; in IsTest::testIsSameMonth this was a real slip, the loop never moved $dt. Fixes #3377
This commit is contained in:
1 parent
8dc8cfa977
commit
b3fc145df6
9 files changed
+143
-11
No files matched your search
@@ -1686,7 +1686,7 @@ class DiffTest extends AbstractTestCase
|
||||
{
|
||||
$from = Carbon::parse('2021-03-27 20:00 Europe/Warsaw');
|
||||
$to = Carbon::parse('2021-03-27 20:00 Europe/London');
|
||||
$from->floatDiffInRealDays($to);
|
||||
$diff = $from->floatDiffInRealDays($to);
|
||||
|
||||
$this->assertSame('2021-03-27 20:00:00 Europe/Warsaw', $from->format('Y-m-d H:i:s e'));
|
||||
$this->assertSame('2021-03-27 20:00:00 Europe/London', $to->format('Y-m-d H:i:s e'));
|
||||
@@ -1751,7 +1751,7 @@ class DiffTest extends AbstractTestCase
|
||||
{
|
||||
$from = Carbon::parse('2021-03-27 20:00 Europe/Warsaw');
|
||||
$to = Carbon::parse('2021-03-27 20:00 Europe/London');
|
||||
$from->floatDiffInUtcDays($to);
|
||||
$diff = $from->floatDiffInUtcDays($to);
|
||||
|
||||
$this->assertSame('2021-03-27 20:00:00 Europe/Warsaw', $from->format('Y-m-d H:i:s e'));
|
||||
$this->assertSame('2021-03-27 20:00:00 Europe/London', $to->format('Y-m-d H:i:s e'));
|
||||
|
||||
Reference in new issue
Block a user