Skip to content

Misrecognition of property data type. #592

@TonnyJe

Description

@TonnyJe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions