-
-
Notifications
You must be signed in to change notification settings - Fork 62
Description
Bug description
If the property is of type DateTimeImmutable and at the same time nullable, the data type is not recognized properly.
To Reproduce
Code snippet, which ends with Nextras\Orm\Exception\InvalidArgumentException, Value for App\Model\Db\User::$birthDate property is invalid. error:
namespace App\Model\Db;
use Nextras\Dbal\Utils\DateTimeImmutable;
/**
* @property int $id {primary}
*
* @property ?DateTimeImmutable $birthDate
*/
abstract class User extends \Nextras\Orm\Entity\Entity
{
}
$user = new User();
$user->birthDate = '2022-09-11T22:00:00'; // here error occurs.
The problem is that Orm recognizes the data type of the $birthDate property as App\Model\Db\DateTimeImmutable instead of Nextras\Dbal\Utils\DateTimeImmutable.
However, if you write the property declaration using UnionType instead of nullable, then everything goes fine. So this ( * @property null|DateTimeImmutable $birthDate ) or this ( * @property DateTimeImmutable|null $birthDate ) will take place as it should and Orm recognizes the data type correctly.
The strange thing is that for scalar data types the nullable notation works fine and thus @property ?string $name works as it should.
Expected behavior
Orm should also be able to recognize the Nextras\Dbal\Utils\DateTimeImmutable data type as nullable.
Versions::
- Orm: v4.0.5
- Dbal: v4.0.4
- PHP: 8.1