The class ClassMetada is not correctly inferring the constructor of ClassMetadaInfo #6729

Open
opened 2026-01-22 15:37:36 +01:00 by admin · 0 comments
Owner

Originally created by @VincentLanglet on GitHub (May 23, 2021).

Hi

Currently

  • new ClassMetadataInfo(\DateTime::class) is inferred as ClassMetadataInfo<\DateTime> by both psalm and phpstan
  • new ClassMetadata(\DateTime::class) is inferred as ClassMetadata<\DateTime> by psalm but as ClassMetadata<object> by phpstan

This is related to this phpstan issue https://github.com/phpstan/phpstan/issues/5057
I don't know how and when the issue will be fixed so one way to fix it temporary would be to repeat the constructor:

        /**
	 * @psalm-param class-string<T> $class
	 **/
	public function __construct(string $class)
	{
		parent::__construct($class);
	}

Since you're using phpstan in this project, you might end with this issue while bumping the phpstan level.
Do you prefer I create a PR here or in https://github.com/phpstan/phpstan-doctrine ?
(The second solution won't fix the issue here since you're not using the library here)

Originally created by @VincentLanglet on GitHub (May 23, 2021). Hi Currently - `new ClassMetadataInfo(\DateTime::class)` is inferred as `ClassMetadataInfo<\DateTime>` by both psalm and phpstan - `new ClassMetadata(\DateTime::class)` is inferred as `ClassMetadata<\DateTime>` by psalm but as `ClassMetadata<object>` by phpstan This is related to this phpstan issue https://github.com/phpstan/phpstan/issues/5057 I don't know how and when the issue will be fixed so one way to fix it temporary would be to repeat the constructor: ``` /** * @psalm-param class-string<T> $class **/ public function __construct(string $class) { parent::__construct($class); } ``` Since you're using phpstan in this project, you might end with this issue while bumping the phpstan level. Do you prefer I create a PR here or in https://github.com/phpstan/phpstan-doctrine ? (The second solution won't fix the issue here since you're not using the library here)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6729