phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
598 stars 97 forks source link

Add api annotation to ObjectMetadataResolver::getClassMetadata #623

Closed VincentLanglet closed 2 weeks ago

VincentLanglet commented 3 weeks ago

Solve https://github.com/phpstan/phpstan/discussions/11975

Since this method is used a lot in phpstan-doctrine rules, it should be allowed for developer to implements customs rule with it too.

ondrejmirtes commented 2 weeks ago

Thank you.

VincentLanglet commented 2 weeks ago

Thanks @ondrejmirtes, do you think the api annotation can be added to the constructor too ? It would allows to write tests without the phpstan "error".:

Creating new PHPStan\Type\Doctrine\ObjectMetadataResolver is not covered by backward compatibility promise. The class might change in a minor PHPStan version.

https://github.com/phpstan/phpstan-doctrine/pull/625

ondrejmirtes commented 2 weeks ago

Definitely not for the constructor. You should get the object from the container.

VincentLanglet commented 2 weeks ago

Definitely not for the constructor. You should get the object from the container.

Then how do I do for writing a Unit test like this one: https://github.com/phpstan/phpstan-doctrine/blob/2.0.x/tests/Rules/Doctrine/ORM/RepositoryMethodCallRuleTest.php#L17

?

ondrejmirtes commented 2 weeks ago

You write a neon config and put the path in getAdditionalConfigFiles.

VincentLanglet commented 2 weeks ago

You write a neon config and put the path in getAdditionalConfigFiles.

Thanks a lot, i found an example with https://github.com/phpstan/phpstan-doctrine/blob/2.0.x/tests/Rules/Doctrine/ORM/MagicRepositoryMethodCallRuleTest.php

self::getContainer()->getByType() works fine !