phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

When are custom type descriptors required?

Open sylfabre opened this issue 2 years ago • 1 comments

Hello

I'm having a hard time figuring out if I need a custom type descriptor 🤔

My custom type is: https://github.com/assoconnect/doctrine-types-bundle/blob/master/src/Doctrine/DBAL/Types/EmailType.php

It extends Doctrine base String type so I guess:

  • It doesn't need a custom type descriptor as I think that phpstan-doctrine can handle the base String type
  • It does need a custom type descriptor as the base String type's convertToPHPValue() and convertToDatabaseValue() methods don't have proper type hints

=> Which one is it?

Whatever your answer is, you may consider improving this section of the README: https://github.com/phpstan/phpstan-doctrine#reflectiondescriptor

And thank you again for this awesome tool 🤩

sylfabre avatar Aug 03 '22 20:08 sylfabre

Also, I'm wondering which type hints are required:

  • Return type hint from both methods?
  • Type hint of the $value argument for both methods?

Looking at the source code of ReflectionDescriptor, I think the answer may be:

  • Return type of the method convertToPHPValue
  • Type hint of argument $value for the method convertToDatabaseValue

But setting an argument type hint would trigger a "Declaration should be compatible with ..." error: image

Should we just ignore this error? Or use an @param annotation?

Thank you for your guidance

sylfabre avatar Aug 03 '22 21:08 sylfabre