mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #6181 from Jack97/date-time-interface-type-reconciliation
This commit is contained in:
commit
358f83d66b
@ -208,6 +208,21 @@ class NegatedAssertionReconciler extends Reconciler
|
||||
return $existing_var_type;
|
||||
}
|
||||
|
||||
if (!$is_equality
|
||||
&& ($assertion === 'DateTime' || $assertion === 'DateTimeImmutable')
|
||||
&& isset($existing_var_atomic_types['DateTimeInterface'])
|
||||
) {
|
||||
$existing_var_type->removeType('DateTimeInterface');
|
||||
|
||||
if ($assertion === 'DateTime') {
|
||||
$existing_var_type->addType(new TNamedObject('DateTimeImmutable'));
|
||||
} else {
|
||||
$existing_var_type->addType(new TNamedObject('DateTime'));
|
||||
}
|
||||
|
||||
return $existing_var_type;
|
||||
}
|
||||
|
||||
if (strtolower($assertion) === 'traversable'
|
||||
&& isset($existing_var_atomic_types['iterable'])
|
||||
) {
|
||||
|
@ -110,6 +110,8 @@ class ReconcilerTest extends \Psalm\Tests\TestCase
|
||||
'notSomeClassWithSomeClassPipeBool' => ['bool', '!SomeClass', 'SomeClass|bool'],
|
||||
'notSomeClassWithSomeClassPipeNull' => ['null', '!SomeClass', 'SomeClass|null'],
|
||||
'notSomeClassWithAPipeB' => ['B', '!A', 'A|B'],
|
||||
'notDateTimeWithDateTimeInterface' => ['DateTimeImmutable', '!DateTime', 'DateTimeInterface'],
|
||||
'notDateTimeImmutableWithDateTimeInterface' => ['DateTime', '!DateTimeImmutable', 'DateTimeInterface'],
|
||||
|
||||
'myObjectWithSomeClassPipeBool' => ['SomeClass', 'SomeClass', 'SomeClass|bool'],
|
||||
'myObjectWithAPipeB' => ['A', 'A', 'A|B'],
|
||||
|
@ -1073,6 +1073,36 @@ class TypeTest extends \Psalm\Tests\TestCase
|
||||
*/
|
||||
function consume($input): void{}'
|
||||
],
|
||||
'notDateTimeWithDateTimeInterface' => [
|
||||
'<?php
|
||||
function foo(DateTimeInterface $dateTime): DateTimeInterface {
|
||||
$dateInterval = new DateInterval("P1D");
|
||||
|
||||
if ($dateTime instanceof DateTime) {
|
||||
$dateTime->add($dateInterval);
|
||||
|
||||
return $dateTime;
|
||||
} else {
|
||||
return $dateTime->add($dateInterval);
|
||||
}
|
||||
}
|
||||
',
|
||||
],
|
||||
'notDateTimeImmutableWithDateTimeInterface' => [
|
||||
'<?php
|
||||
function foo(DateTimeInterface $dateTime): DateTimeInterface {
|
||||
$dateInterval = new DateInterval("P1D");
|
||||
|
||||
if ($dateTime instanceof DateTimeImmutable) {
|
||||
return $dateTime->add($dateInterval);
|
||||
} else {
|
||||
$dateTime->add($dateInterval);
|
||||
|
||||
return $dateTime;
|
||||
}
|
||||
}
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user