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

Closed
opened 2026-01-22 15:37:38 +01:00 by admin · 5 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)
admin closed this issue 2026-01-22 15:37:38 +01:00
Author
Owner

@VincentLanglet commented on GitHub (May 24, 2021):

I saw you did a lot of static analysis on this repository @greg0ire, maybe you can tell me (or ping the right person) to decide if I should do a PR here or in phpstan repository ? :)

@VincentLanglet commented on GitHub (May 24, 2021): I saw you did a lot of static analysis on this repository @greg0ire, maybe you can tell me (or ping the right person) to decide if I should do a PR here or in phpstan repository ? :)
Author
Owner

@greg0ire commented on GitHub (May 24, 2021):

🤔 isn't that going to be fixed by https://github.com/doctrine/orm/pull/8708 ?

@greg0ire commented on GitHub (May 24, 2021): :thinking: isn't that going to be fixed by https://github.com/doctrine/orm/pull/8708 ?
Author
Owner

@VincentLanglet commented on GitHub (May 24, 2021):

Sorry, my first post wasn't clear because I played with my vendor.

Currently

  • new ClassMetadataInfo(\DateTime::class) is not inferred
  • new ClassMetadata(\DateTime::class) is not inferred

After https://github.com/doctrine/orm/pull/8708

  • new ClassMetadataInfo(\DateTime::class) will be inferred as ClassMetadataInfo<\DateTime> by both psalm and phpstan
  • new ClassMetadata(\DateTime::class) will be inferred as ClassMetadata<\DateTime> by psalm but as ClassMetadata
@VincentLanglet commented on GitHub (May 24, 2021): Sorry, my first post wasn't clear because I played with my vendor. Currently - new ClassMetadataInfo(\DateTime::class) is not inferred - new ClassMetadata(\DateTime::class) is not inferred After https://github.com/doctrine/orm/pull/8708 - new ClassMetadataInfo(\DateTime::class) will be inferred as ClassMetadataInfo<\DateTime> by both psalm and phpstan - new ClassMetadata(\DateTime::class) will be inferred as ClassMetadata<\DateTime> by psalm but as ClassMetadata<object> by phpstan. So an issue will still be present with ClassMetadata and phpstan.
Author
Owner

@greg0ire commented on GitHub (May 24, 2021):

I see. I think it should be fixed here, with the repetition you suggested. In order for that constructor not to get removed, please also add something similar to what Marco did in https://github.com/doctrine/dbal/pull/4638

It was already suggested here BTW: https://github.com/doctrine/orm/pull/8633#issuecomment-841678603

@greg0ire commented on GitHub (May 24, 2021): I see. I think it should be fixed here, with the repetition you suggested. In order for that constructor not to get removed, please also add something similar to what Marco did in https://github.com/doctrine/dbal/pull/4638 It was already suggested here BTW: https://github.com/doctrine/orm/pull/8633#issuecomment-841678603
Author
Owner

@VincentLanglet commented on GitHub (May 31, 2021):

Solved in https://github.com/doctrine/orm/pull/8734

@VincentLanglet commented on GitHub (May 31, 2021): Solved in https://github.com/doctrine/orm/pull/8734
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6730